help with quotes, please...

A

Aaron Fude

I have this

<img src="a.jpg" onClick=this.src="b.jpg\"">

and it works. But I like obeying rules so I change it to

<img src="a.jpg" onClick="this.src=\"b.jpg\"">

and it no longer works.

Please note that I really cannot do the alternating
single-quote-double-quote thing is the onClick action is set programatically
and it is hard to detect exactly what's inside.

Thanks!

Aaron Fude
 
E

Evertjan.

Aaron Fude wrote on 27 okt 2004 in comp.lang.javascript:
I have this

<img src="a.jpg" onClick=this.src="b.jpg\"">

and it works. But I like obeying rules so I change it to

<img src="a.jpg" onClick="this.src=\"b.jpg\"">

and it no longer works.

<img src="a.jpg" onClick="this.src=b.jpg;">

as long as you do not use spaces in the second jpg name

======== or =======

<script>
function myB(x){ x.src="b with spaces.jpg"};
</script>

<img src="a.jpg" onClick="myB(this);">

====================
Please note that I really cannot do the alternating
single-quote-double-quote thing is[as?] the onClick action is set
programatically and it is hard to detect exactly what's inside.

That does not seem a valid statement, if you can enter \" you can enter
an apostrophe/single quote programmatically too.
 
M

Michael Winter

Aaron Fude wrote on 27 okt 2004 in comp.lang.javascript:

It wouldn't. HTML doesn't respect backslash as an escape character. It
literally sees \" and interprets it as the end of the attribute. Either
you use single quotes, or the &quot; entity reference.
<img src="a.jpg" onClick="this.src=b.jpg;">

But that wouldn't work, would it. It would be interpreted as: "assign the
value of property jpg of object b, to property src of the current object
(represented by this)". You would have to quote the string.

[snip]
Please note that I really cannot do the alternating
single-quote-double-quote thing is[as?] the onClick action is set
programatically and it is hard to detect exactly what's inside.

That does not seem a valid statement, [...]

I agree.

Mike
 
E

Evertjan.

Michael Winter wrote on 27 okt 2004 in comp.lang.javascript:
But that wouldn't work, would it. It would be interpreted as: "assign
the value of property jpg of object b, to property src of the current
object (represented by this)". You would have to quote the string.

Yyyyyyyyyyyyyyyes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top