Is it possible to append html code in parts via JQuery?

Posted by phpheini on Stack Overflow See other posts from Stack Overflow or by phpheini
Published on 2012-12-18T10:53:40Z Indexed on 2012/12/18 11:03 UTC
Read the original article Hit count: 128

Filed under:

I am trying to append li elements coming from a php file with JQuery. Problem is that the html code needs to be seperately appended to different html IDs according to the key value. Unfortunately as I understood append() can only append correct html with all elements closed. Otherwise it will automatically close the tags. The following code will NOT work as dval contains code like <div><li class="some">Some value</li> and append() will make <div><li class="some">Some value</li></div> out of it. So I was wondering whether there is another way, maybe a function other than append() to be able to append html parts?

$.each(obj, function(key,val)
{
    $.each(obj[key], function(key, dval)
    {                       
        if(key == "text")
        {                   
            $("#" + key).append(dval);
        }           
    })          
});     

© Stack Overflow or respective owner

Related posts about jQuery