0

If I have a var named src, how can I write that into innerHTML?

E.g.

var src = $(this).attr("src");
_html.innerHTML = '<img src="" />';

Place the var src as the img src?

1
  • Why not: var src = this.src; Commented Mar 31, 2011 at 0:41

4 Answers 4

3
_html.innerHTML = '<img src="' + src + '" />';
Sign up to request clarification or add additional context in comments.

4 Comments

Someone actually rated this down?!
That's bizarre - here's a +1 :)
Haha, thank you, just shocked more than anything as I was the first to answer!
I know - SO can be a crazy, crazy world sometimes :)
2

You mean something like this:

var src = $(this).attr("src");
_html.innerHTML = '<img src="' + src + '" />';

Comments

1

It looks like you are using jQuery. If so, you can do it this way:

var src = $(this).attr("src");
var $img = $("<img>").attr("src",src)
$("#yourObject").append($img)

1 Comment

The equivalent would actually be $("#yourObject").html($img)
0

You mean something like this?

_html.innerHTML = '<img src="'+src+'" />';

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.