Reputation: 207
how remove a class after an ajax load using jquery?
First thing, I load an html file containing only list information into a ul id of ul_list
$("#ul_list").load("testListResults");
Next, I try to remove all highlight class file:
$("#ul_list li").removeClass("highLight"); // this is not working, still see the list background high light color.
Next, I try to get the text information of the first list.
$("#ul_list li:first").text(); // this is not working either, showing empty.
Upvotes: 2
Views: 1342
Reputation: 87073
$("#ul_list").load("testListResults", function() {
$("#ul_list li").removeClass("highLight");
$("#ul_list li:first").text();
});
Upvotes: 0
Reputation: 103368
Add your changes to the call back function. This will ensure the scripts are not ran until the ajax load is complete.
$("#ul_list").load("testListResults", function(){
$("#ul_list li").removeClass("highLight");
$("#ul_list li:first").text();
});
With regards to your second point, I don't know what you're trying to do with $("#ul_list li:first").text();
as your not assigning it to a variable, but try .html()
instead:
$("#ul_list li:first").html();
Upvotes: 3