fortherest fortherest - 6 months ago 18
Javascript Question

How to split word with 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

$(".card-box").on("click",function(){
var get_cls = $(this).attr("class");
alert(get_cls);
});


print;


card-box non-clickable offer


but it must be just


offer

Answer

Use spilt() function:

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

$(".card-box").on("click",function(){
   var get_cls = $(this).attr("class");
   var answer = get_cls.split(" ").pop();
   alert(answer);
});