Reputation: 105
I have an asp.net web form with the bootstrap navbar. How can I access the HTML text of a navigation bar using Jquery and change the value before page load? i.e I want to change sign up to "username" before the page is displayed
<ul class="nav navbar-nav navbar-right">
<li><a class="signupnav" href="#" onclick="signUp()" >Sign up</a></li>
<li><a class="signinnav" href="#" onclick="signIn()" >Sign in</a></li>
</ul>
Upvotes: 0
Views: 65
Reputation: 801
You can change it using following code
$(document).ready(function(){
$('ul.nav .signupnav').text("Username");
});
Upvotes: 1
Reputation: 67207
Basically document
's ready event will be fired before window
's load event.
So we can accomplish your task by,
$(function(){
$("ul.nav.navbar-nav.navbar-right").find("a.signupnav").text("username");
// or a less readable version:
// 1. $("ul.nav.navbar-nav.navbar-right a.signupnav").text("username");
// 2. $("ul.nav.navbar-nav.navbar-right > a.signupnav").text("username");
//Your other code below...
//...
});
And this $(function(){...});
is a shorthand for $(document).ready(function(){...});
. So don't confuse with that.
Upvotes: 2