简体   繁体   中英

how to append the data using jquery?

I need to add the value into the span using dom. But now i am using string manipulation. how to change this into the dom or append the value . i need to get the return value in html formate using dom.

Define layer.id as some text and this will get replace in all span element content

$.each($("span"),function(){
$(this).html(layer.id);
});

Thanks

您可以像下面这样追加:

$('.ClassName').append('<p>Test</p>');
$('#id').after('<p>Test</p>');
$('#id').before('<p>Test</p>'); 

Try with this:

$("<li class='" + liClass + "'>" + preElement + 
  "<label for='" + layer.id + "'>" + layer.name + "</label>").appendTo('ul.class'); 
                                                               //----------^^^^^ 
                                                               // use the id 
                                                               // or class of 
                                                               //the specific ul

use appendTo() instead return and append it to your element.

(as i see you are returning li then append it to the ul)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM