user575363
user575363

Reputation:

Add HTML elements into an object

I want to add HTML elements in form of variable into an object by using JQuery *or without.

HTML elements

<a href="#" class="edit">EDIT</a>

Now I am just using this elements as variable...

var link = "<a href="+'"'+"#"+ '"'+ " class="+'"'+"edit"+'"'+">EDIT</a>";

Obj.addvariable(link) ?????????  // This Object could be any ID Or Class Or Div 

Upvotes: 1

Views: 6249

Answers (4)

Gaurav
Gaurav

Reputation: 28755

You can use this in jquery as

$('#elementId').append(link);   // with id
$('.elementClass').append(link);   // with class, append to all elements of this class

Upvotes: 0

Headshota
Headshota

Reputation: 21449

you can add values to any properties even if they don't exist. javascript automatically creates them for you

Obj.anyProperty = 'new value';

if you want to append an element to a html element you can either use append:

$(element).append(link);

or appendTo:

$(link).appendTo(element)

Upvotes: 0

alex
alex

Reputation: 490263

jQuery

$('body').append(link);

JavaScript

var element = document.createElement('a');
element.href = 'a';
element.className = 'b'
element.innerHTML = 'EDIT';
document.body.appendChild(element);

Upvotes: 1

archil
archil

Reputation: 39501

I don't exactly understand your question, but maybe jquery data is what you are looking for

Upvotes: 0

Related Questions