Hi Cherry - I enjoyed reading your blog. It's especially interesting &
informative to read what issues jQuery newcomers come across.

One issue that it seemed you may not have grasped is when to escape
characters. This isn't something specific to jQuery - it's actually a
Javascript-wide issue, but you run across it a lot with jQuery.

It's simple once you realize what's going on: You only need to escape
characters within data when they are the same as the character you're
using to surround (define) the data. Basically you are preventing
Javascript from being confused about the start & end of the data.

Simplifying the "replace text with an image" example in your blog a
bit:
$('h1').append('..........');
...Here you are using single quotes to define the parameter data for
append, so you only need to escape any single quotes that are within
your parameter data. There are none, so it's not necessary to escape
anything. For consistency's sake, in your example the double quote
after fullinfo.html is missing a backslash. But, it doesn't matter
since again for that example, you don't need to escape double quotes
at all.

You've inadvertently discovered this: it's a great idea to use single
quotes to define the parameter data when using HTML code, since
usually you don't need to escape anything (unless there are single
quotes in your HTML). If you're defining a something like a sentence
containing single quotes, it's best to use double quotes to define it
since you don't have to escape the single quotes:
$('h1').append("Here's a sentence that's got some single
apostrophes.");
...again because I'm using double quotes to define the start/end of
the sentence, only double quotes within the sentence will cause
problems. There are none, so I'm all set.

Taking one more look at your example, I've changed the title to
contain some single quotes. Both of these examples will work, but I
prefer the 2nd one since there's a lot less escaping to be done.

$('h1').append("<img src=\"/images/headertext.gif\" alt=\"alt text\"
title=\"Here's a great site. It's awesome.\" longdesc=\"http://
something.com/fullinfo.html\" />");
$('h1').append('<img src="/images/headertext.gif" alt="alt text"
title="Here\'s a great site. It\'s awesome." longdesc="http://
something.com/fullinfo.html" />');

Hope that makes (more?) sense.

-Wick
CarComplaints.com


On Feb 3, 11:54 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Seriously, I beg for your opinions/corrections/suggestions ...
>
> http://cherry.austin.googlepages.com/home
>
> Cherry

Reply via email to