For example > look at the code below

<div class="s1 s2 s3">
//content goes here
</div>

This class is added dynamically, so i like to know how the find the second class (say for example : "s2").

and do some action..

Recommended Answers

All 4 Replies

What do you undestand the word "find"? If you must to get a element which have class "s2"

$(".s2")

Hey radow thanks for your reply.

simply we say this "s2 class" is added dynamically, we dont know what is that. My question is how to remove the second or last class (whatever it may be) in a div

You can following code:

var clases = $(".s1").attr("class").split(" ");//get all classes for element with class="s1"
 var className = classes.pop();//if must remove last class
 var className = classes[1];//if must remove 2 class
 $(".s1").removeClass(className);//remove class

I hope this help.

Hey @radow thankyou very much,
you solved my problem

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.