jQuery working in console but not in original code -


i have tried following code add href tag inside td. working fine while in console. when try same in code not working. can tell me reason?

<script>     $("table tbody tr td a").attr('href','http://www.google.com');  </script> <table>     <tr>         <td><a >hai</a></td>     </tr> </table> 

use document.ready()

$(document).ready(function() {     $("table tbody tr td a").attr('href','http://www.google.com'); } 

you need ensure document loaded, before try manipulate dom.

more info @ : http://api.jquery.com/ready/


Comments