0

I am using the code below to create an image with a css class and put it in a div (imagepath1) .

this.imagePath1.innerHTML = "<img src='" + "../path/imagename" + "' class='classname'>";

It is not able to find the image path, as I can see in the DOM element and resource is also not available when seen through "inspect element".

Any clues how to do this?

Thanks, kk

4
  • Well if the inspected code looks OK then there must be a problem with the URL of the image. Does it work? Commented Mar 20, 2013 at 11:24
  • Depending on your doctype the markup may be invalid. Close the <img/> tag. Commented Mar 20, 2013 at 11:34
  • Please make a jsfiddle.net so we can play around with it. Commented Mar 20, 2013 at 11:36
  • what is the actual image path that you are using? Commented Mar 20, 2013 at 11:42

1 Answer 1

1

1)Be sure the path you are coding is relative to your html document ( not to your javascript document)

2) The img tag is fine without closing slash for html (no closing tag in is ok for HTML but some browser may use the XHTML syntax where the tag must be properly closed.

NOTE

Both possible solutions are made under the consideration that your javascript statement is in the correct context concerning the use of the this keyword. which as you know, is related to the caller and context and not to the function.

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

1 Comment

It seems to be working after I gave the full path of the image:)

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.