I have the following css
<div class="test"></div>
I want to set string "test" in variable like this:
var $stringvalue = $('.test').class(); /*but seems wrong statment*/
I have the following css
<div class="test"></div>
I want to set string "test" in variable like this:
var $stringvalue = $('.test').class(); /*but seems wrong statment*/
You can use the .attr()
function.
var $stringvalue = $('.test').attr("class");
class attribute
on the original DOM.You can also use the native className
property to get an array of class names.
var classes = $('.test')[0].className.split(/\s+/)`
Use .attr()
var $stringvalue = $('.test').attr('class');
attr('class')
will get the class attribute of div
with class
of test
.
var $stringvalue = $('.test').class();
should be
var $stringvalue = $('.test').attr('class');