I have the following code, written using jQuery:
var strval = '22'
$("#quicknote").attr("href",
"javascript:location.href=/'http://site.com/notes/add?projects=/'+ strval")
Which results in the following attribute:
<a href="javascript:location.href='http://site.com/notes/add?projects='+'strval'"
id="quicknote">
But, what I want is:
<a href="javascript:location.href='http://site.com/notes/add?projects='+'22'"
id="quicknote">
Any jQuery wizards know how I might achieve this result?
Try:
Note the position and type of quotes.
On a side note, I’m not exactly sure why you wouldn’t to do this instead:
ie theres no need for Javascript in your example.
Lastly, since you are using jQuery anyway I wouldn’t put Javascript in the href like this either. Instead add a
click()handler: