| re: Escaping quotes for innerHTML in Mozilla
Ted Weatherly wrote:[color=blue]
> Hello,
>
> I want to dynamically create a table cell with a textfield in it. The
> value for the textfield can have quotes. e.g. ["test" ]
>
> I have this snippet of javascript code:
>
> var td = document.createElement('td');
> var cellMarkup = '<input value=""test"">';
> td.innerHTML = cellMarkup;
> alert("cellMarkup = " + cellMarkup + "\n" +
> "td.innerHTML = " + td.innerHTML);
>
> On Mozilla, the text in alert box shows up as:
>
> cellMarkup = <input value=""test""> <-- Good
> td.innerHTML = <input value="test"> <-- Bad
>
> In summary, I am trying to escape the quotes in "test". The escaped
> quotes disappear, however, when I set the markup in innerHTML. The
> string "test works correctly though. And on IE the escaping the
> quotes works all the time.
>
> Does anyone have hints on how to get this to work on Mozilla? I've
> already tried escaping with \" and that doesn't work either.
>
> Thanks in advance,
> -Ted[/color]
A work around would be to change the " to a ' and then escape it using \
so it comes out as \'. Should work
Gary |