javascript - jquery use next and each to change the url of the elements -
i have 4 links points 4 pages
<a href="asdf">asdf</a> <a href="asdfer">1244</a> <a href="iuiuy">qwer</a> <a href="asdfasdf">asdfqew</a>
i want add number current url href of next elements based on current page url argument
(ie) if @ page "asdf" other 3 links needs add sum number
<a href="asdf">asdf</a> <a href="asdfer/123">1244</a> <a href="iuiuy/123">qwer</a> <a href="asdfasdf/123">asdfqew</a>
here code used
var pathname = window.location.pathname; var split = pathname.split("/")[4]; console.log(jquery("#pagetabs li a").each().next().attr('href')); if(split.match(/^\d+$/)){ jquery("#pagetabs li a").each(function(){ href = jquery(this).attr('href'); newhref = href+'/'+ split; jquery(this).next().attr('href',newhref); }); }
but error getting
typeerror: undefined http://example.com/misc/jquery.js?4 line 12
is wrong code
var split = 1563; // number current url if(split){ $("#pagetabs li a").each(function(index){ var $this=$(this); if(index!=0) $(this).attr('href',$this.attr('href')+'/'+ split) }); }
Comments
Post a Comment