Reputation: 75
function Login(){
contentType: "get",
dataType: 'json',
success: function(data) {
$("#login").hide(); //hide the login button
$("#logout").show(); //show the logout button
$.mobile.changePage("#home"); //show the menu
},
error: function (response) {
var r = jQuery.parseJSON(response.responseText);
console.log(r);
alert("Error:" + r.error.text);
}
});
}
I have the above function to hide the login button however using jqm i have many login buttons on different pages all with the same id. When this function is accessed however only one of those buttons is deleted. It has something to do with every log in button having the same id however im not sure of any other way where i can delete all log in buttons without them having a different id and then hiding all on each individual page
Upvotes: 0
Views: 131
Reputation: 12343
Instead of using just the ID as the selector, how about accompany the element tag as well?
$('button#login').hide();
Or multiples!
$('button#login, div#login, input#login').hide();
JSFiddle: http://jsfiddle.net/wyze/HS3zS/1/
Upvotes: 0
Reputation: 17630
A feature of IDs is that there is supposed to be one and only one element with a given ID. You might try using a class instead. Your HTML would change to be something like this:
From:
<button id="login" class="foo">Login</button>
to:
<button class="foo login">Login</button>
and your new jquery hide would be:
$(".login").hide();
Upvotes: 2