Reputation: 5734
trying to incorporate a jQuery script into a Wordpress site.
I created a custom page in my theme and added the following in the body tag:
<body>
...
<div id="msgid"> hello there
</div>
...
</body>
I also created a test.js file with the following:
$(document).ready(function(){
$("#msgid").html("Hello world.");
});
I am loading the test.js in the footer.
I was expecting to see Hello world. in the div. But it doesn't show anything.
Any ideas?
Thanks.
Upvotes: 0
Views: 583
Reputation: 740
Wordpress by default uses the noConflict version of jQuery, which means it doesn't load jQuery to the $ sign.
You can do this:
jQuery(document).ready(function($){
//inside of here you passed in the $ sign to be used as an alias of jQuery
$("#msgid").html("Hello world.");
});
See here for more details on jQuery's noConflict function: http://api.jquery.com/jQuery.noConflict/
Upvotes: 5