views:

71

answers:

1

i am developing a jquery script. i am use this

"$("a").html(" alt='example' src='example.jpg> ")" to dynamically adding a "img" 

tag inside "a" tag. (note, src='example,jpg has no closing single quote ).

in firefox, "img" tag showed up, but in IE and opera "img" tag did not show up, so i have spent 2 hours try to find out why? then finally found out that "closing single quote problem".

my question is, is there any tool to prevent this type of error?

by the way how can i input html tag into my post?

+1  A: 

I think some of your snippet was eaten up, otherwise it doesn't do anything. Considering that this is dynamic code, the only tools that would be capable of finding an error like this would be some validator which is javascript-aware.

A way to avoid this error would be to set the src attribute using jQuery:

var img = $("<img>");
img.src = "example.jpg";
$("a").append(img);

This way your text editor would probably pick up the mismatch, and if not you'd get an error when the JS is evaluated.

sebnow
wow, i do not know $("<img>") can create a new "img" tag. thank you very much