javascript - HREF being modified beyond my control...? -


i'm not sure if jquery, javascript or quirk in browser consider code:

for(rowidx=0;rowidx<theresultset.rows.length;rowidx++) {   thisline = $("#testtemplateli").clone().attr({'id':'test_'+rowidx}).appendto("#test_exerciselistul");   thisline.find('[href*="#pageexercise_exercisenumber"]').each( function(i) {this.href = this.href.replace('exercisenumber', rowidx)} ); } 

the goal of code above clone list item (<li>, embedded below) html fragment, modify address anchor elsewhere on page , insert unordered list (<ul>). works using wonders of jquery. problem once it's been modified, anchor doesn't seem work. after mod href programattically, returns full url, not anchor reference. example:

<ul id='testtemplate' style="display:none">      <li class='arrow' id='testtemplateli'>         <a href='#pageexercise_exercisenumber'>  <!-- beast in question -->             <div class='labelclass test_labelcontainer'>                 <table height=100% width=100%>                     <tr valign='center'><td align='center'>exerciselabel</td></tr>                 </table>             </div>             <img id='test_checkmark_exercisenumber' class='test_checkmark_off' src="assets/checkmark.png" width=60px height=54px>             <div id='test_item_exercisenumber' class='test_exnamecontainer'>                 <table height=100% width=100%>                     <tr valign='center'><td>exercisename</td></tr>                 </table>             </div>         </a>     </li> </ul> 

so, 2 things happening. one, modified anchor not working , two, should modify "href='#pageexercise_exercisenumber'" "href='#pageexercise_0'" (or whatever current row index ('rowidx') modifies to: "href='http://www.mydomain.com/themainpage.php#pageexercise_0'".

i need way tell javascript stop "helping" me on href. issue #1, think it's related #2.

thanks in advance,

scott.

this.href 

will return fully-qualified url anchor points to.

you can use jquery's attr function return want:

var $this = $(this); $this.attr("href", $this.attr("href").replace('exercisenumber', rowidx)); 

here's post explaining how .attr("href") "normalized"


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -