Q:

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

A:

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');

A:

When we need to get the html string from some DOM component we extracted from its parent, (eg: sortable helper), then we can convert that string to jquery object first. 
example:
var thehtml = $(ui.helper).html();
    thehtml = $(thehtml); // convert to jquery object
    thehtml.addClass("yourClass"); // we can then assign new class

    ui.helper.replaceWith(thehtml); // do something you want with it

In your case
var someVar = '<i class="firstClass"></i>'; // Html Markup to be used later. 
    someVar = $(someVar); // convert to jquery object
    someVar.addClass('secondClass');

