Dear All,

I am trying to store a predefined div with a class in a variable using jQuery, Please find my below code and let me know whether it is right or not.

loader : $("<div/> + {class:'test'}")

thanks in advance.

Member Avatar for LastMitch

Please find my below code and let me know whether it is right or not.

Can't answer your question regarding about your code because you didn't provided enough code to determine whether it works or not.

So this is the only code that I can think of:

jQuery:

var vname = 'This is my variable';

$('#variable').prepend('<div id="' + vname + '">'+ vname +'</div>');

html:

<div id="variable">variable</div>

hey lastMitch,

thanks for your respone, that is fine. But my question is whether it is the right format .I saw one. like this.

Code is like

    res
    {
    loader : $("<div/> + {class:'test'}")
    }

    res.loader.append('somediv');
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.