Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery add class in a variable containig html string

I have this variable and i want to add a class to it. I tryed this method, but this defenetly is not working

var someVar = '<i class="firstClass"></i>';// Html Markup to be used later.
    someVar.addClass('secondClass'); 

I need a different method to adding a new class to the html markup.

Thanks

like image 929
Anghel Gabriel Avatar asked Jan 15 '23 13:01

Anghel Gabriel


1 Answers

You can only use addClass on a HTML element so you need to set your variable to be a DOM element (e.g. $('<i>')):-

var someVar = $('<i>', {'class': 'firstClass'});
someVa.addClass('secondClass');
like image 104
drmonkeyninja Avatar answered Jan 23 '23 12:01

drmonkeyninja