Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select element with jquery that has multiple classes

$(".status").attr("rel");

.status can have up to three other additional classes added to it. .online, .away, .offline

if I do this:

$(".status.online").attr("rel");

it works when status has online as a second class, but not when it's been changed, how can I do this and it not matter what other classes it has?

like image 950
Dylan Cross Avatar asked Dec 22 '22 02:12

Dylan Cross


1 Answers

If the element has multiple classes you can still select it just by using any of those class. So your selector is correct you don't have to change anything.

$(".status").attr("rel");

If you think that the class can change and it can have any or these classes(online, offline, away) along with status try this.

$(".status.online, status.offline, .status.away").attr("rel");
like image 54
ShankarSangoli Avatar answered Jan 05 '23 21:01

ShankarSangoli