javascript - jQuery code isn't working when loading the page -


i'm having issue. have html page has javascript code , jquery code in same script tag.

here html javascript , jquery:

<!doctype html> <html lang="en">  <head>   <meta charset="utf-8">   <meta name="viewport" content="width=device-width, initial-scale=1.0">   <meta name="description" content="">   <meta name="author" content="">    <title>page</title>    <!-- css -->   <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css">   <link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />   <link href="css/nivo-lightbox.css" rel="stylesheet" />   <link href="css/nivo-lightbox-theme/default/default.css" rel="stylesheet" type="text/css" />   <link href="css/animate.css" rel="stylesheet" />   <link href="css/style.css" rel="stylesheet">    <!-- javascript , bootstrap -->   <script src="js/jquery.min.js"></script>   <link href="js/bootstrap.min.js" type="text/javascript">   <link href="js/modal.js" type="text/javascript">    <!-- template skin -->   <link id="t-colors" href="color/default.css" rel="stylesheet">     <script>      <!-- here pure javascript code -->  $(document).ready(function() {   var table = $('#tablebody tr td');    table.on("click",function() {     table.removeclass("test-class");     $(this).addclass("test-class");   }); }); </script> 

my problem is: when page loads, jquery function not work, when copy function , paste on browser's console, works perfectly.

note: when put alert on browser's console works. means jquery loading page.

what missing?

thanks in advance.

try code

$('document').on("click",'#tablebody tr td',function() {   var table = $('#tablebody tr td');   table.removeclass("test-class");   $(this).addclass("test-class"); }); 

i dont know if td element created in code or static html. if td or table dynamic, dom not know because when browser runs, keeps record of original html.

dom lose tracking, using format on('click','#target', func()) make dom go , find target again.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -