Reputation: 13
I'm looking to add some content inside an existing div.
I'm getting the amount of images contained in another div with the following line
var n = $("div#content img").length;
I've got that element I'm trying to insert content into
<div id="imgCount"></div>
I do know that I can insert the value of my n
var into it by doing this
$("#imgCount").text(n);
I do know as well that I can insert HTML into it by doing the following
$('#imgCount').append('<a href="#">sometext</a>');
but I'd like to combine both of them to get the following result :
<div id="imgCount"> <a href="#"> n </a> </div>
Upvotes: 1
Views: 7557
Reputation: 808
Did you try something like this?
$('#imgCount').append('<a href="#">' + n + '</a>');
Upvotes: 1
Reputation: 32581
$('#imgCount').append('<a href="#">'+n+'</a>');
Something like this?
Upvotes: 4
Reputation: 16544
Ok this is a very very basic one. You should get started with Javascript basics soon
$('#imgCount').append('<a href="#">' + n + '</a>');
Upvotes: 1