jquery replace query -


i alter href attribute anchor tags within particular div.

<div id="xyx">     <ul>          <li><a href="xyz/-1"/></li>         <li><a href="abc/-1"/></li>         <li><a href="cab/-1"/></li>     </ul> </div> 

i replace with:

<div id="xyx">     <ul>          <li><a href="xyz/-2"/></li>         <li><a href="abc/-2"/></li>         <li><a href="cab/-2"/></li>     </ul> </div> 

i.e. want replace -1's -2's.

how can done in jquery?

use attr method, , pass function it. executes function on each element within jquery set, changing provided attribute value returned function.

jquery passes current value of attribute second parameter of function (which current "href" value in case), replace -1 occurances -2.

$('#xyx a').attr('href', function(i, href) {      return href.replace('-1','-2');  }); 

Comments

Popular posts from this blog

jQuery clickable div with working mailto link inside -

WPF: binding viewmodel property of type DateTime to Calendar inside ItemsControl -

java - Getting corefrences with Standard corenlp package -