I want to add HTML elements in form of variable into an object by using JQuery *or without.
<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
$('body').append(link);
var element = document.createElement('a');
element.href = 'a';
element.className = 'b'
element.innerHTML = 'EDIT';
document.body.appendChild(element);
我不太了解您的问题,但也许jquery数据正是您要寻找的
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)
You can use this in jquery as
$('#elementId').append(link); // with id
$('.elementClass').append(link); // with class, append to all elements of this class
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.