JavaScript Beginner!


The Follow stateman has something that i can´t figure what it does:

var fullLink = “href=\”“”\" target=\“”“\” onClick=\“clickOnLink('”+this.getID()+“\', '”“‘,’”“');return false;\”";

What is a Regular Expression?

What is the “\” in “href=\”…?

I just don´t know!

can you help me?


Your variable fullLink is being generated dynamically. it should have an <a element at the beginning, before the href=.

The \" is a way of preventing the write to page process from incorrectly thinking that the " is the end of the string started at "href=.

The is a way of filling in the correct href link detail from the information stored in the page object model before the page write. It should look something like “”.

The onclick suggests that this dynamic link may have been designed to carry out two functions; one by way of the onclick and the second via the <a href. It might also be used to make sure that people with and without javascript enabled can still use this link.

The return false; suggests that the normal behaviour of the first href is being prevented. It all looks a bit of a mess, but its hard to tell untill the missing info is made available.

A Regular Expression is a method of finding if specific patterns occur in a string. For instance, checking the input format of an email address to make sure it conforms to the standard.

Lets look again:

var fullLink = “href=\”“”\" target=\“”“\” onClick=\“clickOnLink('”+this.getID()+“\', '”“‘,’”“');return false;\”";

in the “href=\”" the \" it tells me that the " is not the end of the string so why in the portion onClick=\" don´t have two " like onClick=\“”? and more in the portion (‘“+this.getID()+”\’… why have the \’ again if the others statemants like next …\‘, ‘“”’,’“”‘)… doesn’t have the \’???

I am just beginning and i am very confuse!!

Shouldn´t it be something like “href=\”“”\" target=\“”“\” onClick=\“clickOnLink('”+this.getID()+"',…

i mean why have the \'… in this portion if the rest don´t ???


When you are writing a string of code to a page the positions of the " and ’ are important as end markers. For instance you can use the following document.write statement within a javascript script:
document.write(“hi there”);. The " in this case is indicating the ends of the string.

If you want to use the character " somewhere within this string you need to escape it, so that the script knows that it is not the end of the string, but a part of it. Here is an example using the \’ and \" characters:
document.write(“The town\'s horse \“harry\” ran away”);

The characters \’ and \" in this case are interpreted as being punctuation marks, not end of string markers. The same thing applies to the string of code that was originally posted.