1

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 
1
  • @all Thanks to all of you. resolved :) Commented Apr 6, 2011 at 7:25

4 Answers 4

1

jQuery

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

JavaScript

var element = document.createElement('a');
element.href = 'a';
element.className = 'b'
element.innerHTML = 'EDIT';
document.body.appendChild(element);
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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)

Comments

0

You can use this in jquery as

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.