Clearing <a> href after loading page with jquery

I am trying to slightly modify the wordpress template. At the moment, the function returns a link to the article, I'm trying to replace this link so that instead of redirecting to another page, it simply inserts the article and loads it.

To do this, I need to reset to bind href after the page loads.

This is the part of the code that interests me:

<?php the_content( __('<img class="readmore" src="/images/readmore.png" title="poo"></img>', 'twentyten' ) ); ?> 

returns:

 <a class="more-link" href="http://henryprescott.com/undgraddissintro/#more-12"> <img title="poo" src="/images/readmore.png" class="readmore"></img></a> 

However, I want to change this so that instead of a script, a transition to a new page is performed.

So I tried to run this:

 $(document).ready(function(){ $("a.more-link").css("href", "#"); alert($("a.more-link").css("href")); } 

It does nothing, and the warning returns "undefined".

Where am I going wrong, thanks!

+4
source share
3 answers

You are trying to change an attribute using a CSS command, which is incorrect.

 $(document).ready(function(){ $("a.more-link").attr("href", "#"); alert($("a.more-link").attr("href")); } 
+5
source

Use attr() instead of css() .

The css method is for getting or setting CSS properties (e.g. margin , color , font-size , etc.). The attr method is designed to get or set HTML attributes such as href , src , etc.

+15
source

css (), if only to add inline css try attr () in this case

 jQuery(document).ready(function(){ jQuery("a.more-link").attr("href", "#"); alert(jQuery("a.more-link").attr("href")); return false; } 

returns false to avoid page reload .;)

0
source

All Articles