1

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>

3 Answers 3

4
$('#imgCount').append('<a href="#">'+n+'</a>');

Something like this?

Sign up to request clarification or add additional context in comments.

Comments

1

Ok this is a very very basic one. You should get started with Javascript basics soon

$('#imgCount').append('<a href="#">' + n + '</a>');

1 Comment

weird that's what i did in the first place but didnt work out. now it does.
1

Did you try something like this?

$('#imgCount').append('<a href="#">' + n + '</a>');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.