jeremyll
asked on
jquery addClass in second last <li> tag
I want to add a class to the second last <li> element in every <ul> tag.
I've tested this in a html page which works.
$('ul.sub_menu li').last().prev().addClas s('secondL ast');
but it doesnt' work when i place this into the default.aspx file
website: http://asqastage.esa.edu.au/
this ul.submenu is in the top menu nav (i.e. Home, About Us, The national system, etc.)
I've tested this in a html page which works.
$('ul.sub_menu li').last().prev().addClas
but it doesnt' work when i place this into the default.aspx file
website: http://asqastage.esa.edu.au/
this ul.submenu is in the top menu nav (i.e. Home, About Us, The national system, etc.)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Good question gurvinder372. My bad sorry guys! I placed it in the <head> tag in default.aspx instead of after the </body> tag.
That should be the case right?
I've tried it and it worked.
That should be the case right?
I've tried it and it worked.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Putting it after the </body> is not valid. It could be placed immediately after it instead.
If you wanted to put it in the head, you could use the "ready()" event handler:
If you wanted to put it in the head, you could use the "ready()" event handler:
$(document).ready(function(){
$('ul').each(function(){
$(this).children(':last-child').prev().addClass('secondLast');
});
});
hello Bro!
Whats the status of the problem
The code is fine and should be work
make sure that would be in <Head> tag and also if you want to add on proper location then add this in ready function like this
Regards,
Asif Ahmed khan
Whats the status of the problem
The code is fine and should be work
$('ul').each(function(){
$(this).children(':last-child').prev().addClass('secondLast');
});
make sure that would be in <Head> tag and also if you want to add on proper location then add this in ready function like this
$(document).ready(function(){
$('ul').each(function(){
$(this).children(':last-child').prev().addClass('secondLast');
});
});
Regards,
Asif Ahmed khan
ASKER
There's notthing wrong. I tried to award points to Kravimir and gurvinder372 12 hours ago, but it's created a close request instead.
experts exchange webstie was down for a while earlier today.
experts exchange webstie was down for a while earlier today.
ASKER
legendary
ASKER
To be honest I rekcon Kravmir's and gurvinder372's and even my code (i.e. $('ul.sub_menu li').last().prev().addClas
should be working because I've tested it in a plain html page which works!
Something amiss.