I'm trying to use JQuery in WordPress pages but it doesn't work:
<script>
$('a[href="http://domain1"]').attr("href","http://domain2");
</script>
I'm trying to use JQuery in WordPress pages but it doesn't work:
<script>
$('a[href="http://domain1"]').attr("href","http://domain2");
</script>
You must use jQuery keyword instead of $ shortcut when you put JQuery in WordPress pages..
and eliminate new line characters and unnecessary spaces as well like shown below:
<script>jQuery(document).ready(function($){$('a[href="http://domain1"]').attr("href","domain2");});</script>
Normally jQuery is conflict with Wordpress since they're both using $, try to do:
jQuery(document).ready(function($) {
$('a[href="http://domain1"]').attr("href","http://domain2");
});
or put your code inside a closure:
(function($){
$('a[href="http://domain1"]').attr("href","http://domain2");
})(jQuery);