How to pass a value to <a href ="">

R

Rob

I have values like
<span id = "URL">URL</span>
where the id "URL" is generated by javascript automatically.

I know in JSP, one can pass the value directly like <a href = <%=URL>>

but how do I do this for javascript?
 
E

Evertjan.

Rob wrote on 18 okt 2007 in comp.lang.javascript:
I have values like
<span id = "URL">URL</span>
where the id "URL" is generated by javascript automatically.

I know in JSP, one can pass the value directly like <a href = <%=URL>>

but how do I do this for javascript?

It is just the same in serverside Javascript:

<a href = '<% = URL %>'>

For clientside javascript, that seems not your Q, use the DOM.
 
L

Luke Yan

you can use JS Dom model to access elements in HTML.

sample:
<a id="sampleLink" href="http://google.com"></a>

document.getElementById("sampleLink").getAttribute("href"); // which returns
"http://google.com"
document.getElementById("sampleLink").innerText = "Google";
 

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,150
Messages
2,570,853
Members
47,394
Latest member
Olekdev

Latest Threads

Top