Reputation: 2674
i'm a javascript, jquery newbie :) how can i make a loop here on all the href within #rfr-topnav using javascript or jquery? thanks in advance.
<script type="text/javascript">
$(document).ready(function(){
var sel="#rfr-topnav a[href*='#root#']";
var href=$(sel).attr('href');
var rootUrl = $('#ctl00_RootUrlId').attr('value');
var newhref=rootUrl+href.substr(href.indexOf('#root#')+6);
$(sel).attr ('href',newhref);
});
</script>
Upvotes: 2
Views: 989
Reputation: 324567
Refactoring slightly, I think this is what you want:
$(document).ready(function(){
var $sel = $("#rfr-topnav a[href*='#root#']");
var rootUrl = $('#ctl00_RootUrlId').val();
$sel.each(function() {
var $this = $(this), href = $this.attr('href');
$this.attr('href', rootUrl + href.slice(href.indexOf('#root#') + 6));
});
});
Upvotes: 1