Skip to content Skip to sidebar Skip to footer

How Do I Append Both An Element And Text To A Div In Jquery?

I'm using jQuery and trying to append both an element and some text to an existing div element. However, when I try this $('').appendTo(gMenuItemInnerD

Solution 1:

var gMenuItemInnerDiv = $('#something');
var name = "<b>Yay</b>";

$('<img src="/img.png" />').appendTo(gMenuItemInnerDiv);
gMenuItemInnerDiv.append( document.createTextNode(name) );
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="something"></div>

Solution 2:

Did you try something like this ?

$('<img src="/img.png" />').appendTo(gMenuItemInnerDiv);
$('<span>' + name +'</span>').appendTo(gMenuItemInnerDiv);

:)

Post a Comment for "How Do I Append Both An Element And Text To A Div In Jquery?"