fortherest fortherest - 2 years ago 120
jQuery Question

How to get last class by Jquery

my class is like this;

<div class="card-box non-clickable offer"></div>

and I just want to get offer class I don't want to get before offer what should I do ?

my functions is like this

var get_cls = $(this).attr("class");


card-box non-clickable offer

but it must be just


Answer Source

Use spilt() function:

split() will split the entire string into array and pop() will rerturn last element thats offers

   var get_cls = $(this).attr("class");
   var answer = get_cls.split(" ").pop();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download