Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everyone , I need to select the last element by class in JQuery And change the css for another element (Id)

JavaScript
var last = $(".Pagin_1").last().$("#next").css("background-color", "green");


Something like that code

What I have tried:

I try this code
JavaScript
$(".Pagin_1").last().$("#next").css("background-color", "green");
Posted
Updated 23-Oct-22 22:26pm
Comments
Member 15627495 17-Oct-22 3:06am    
hello !


$(selectors).$(selector 2 ) can not be chain like you do.
In jquery , $ is your page DOM, and the selector the tag 'area' you want ton act on.
$(".pagin_1 #next").last().css("attribute","value"); will be understandable by jquery


https://api.jquery.com/last/

1 solution

Quote:
If you're trying to set the next to last elements background-color try;

JavaScript
$(".Pagin_1").last().prev().css("background-color", "green");


If you are trying to set the last element try;
JavaScript
$(".Pagin_1").last().css("background-color", "green");


If you are trying to set both .Pagin_1 and #next you need to do it separately.
JavaScript
$(".Pagin_1").css("background-color", "green");
$("#next").css("background-color", "green");


If neither of these I can't see what you're trying to do!
 
Share this answer
 
v2
Comments
Abdulmajeed Alotaibi 24-Oct-22 4:27am    
I was trying To change the next button only if they reach the last element but I found out it needs more coding than this
Member 15627495 24-Oct-22 8:32am    
$(".Pagin_1 , #next").css("background-color", "green"); // it pass

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900