Kerwin
Kerwin

Reputation: 339

Jquery .html() with 2 variables

convopic.addClass('convo-pic')
img.attr('src', base_url+'/assets/img/users/'+msg.server.profile_img)
convopic.html(img)
bubble.addClass('bubble startmsg')
bubble.text(msg.client.data.message)
$('.mydiv').html(convopic+bubble)

my expected output is

<div class="mydiv">
<div class="convo-pic">
<img src="'+base_url+'/assets/img/users/'+msg.server.profile_img+'"></img>
</div>
<div class="bubble startmsg">'+msg.client.data.message+'</div>
</div>

But it returns [object][object], any idea how handle 2 variables inside .html() ? I'm using this way to prevent xss.

Upvotes: 0

Views: 24

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388416

You can use .add()

$('.mydiv').html(convopic.add(bubble))

or use .html() and append()

$('.mydiv').html(convopic).append(bubble)

Upvotes: 1

Related Questions