I have some dynamically created links in my pages and what I need to do is when I click on the link, I should pass the name of the link to another page. So, please show me a way to accomplish this. Thanx in advance :)
-
3Can you explain more detalied what you want to do? What means "should pass the name of the link to another page"?Mihran Hovsepyan– Mihran Hovsepyan2011-03-19 16:22:13 +00:00Commented Mar 19, 2011 at 16:22
-
When I said name of the link i.e <a href = "some website">Name_of_the_link</a> . This is name of the link !Mojo_Jojo– Mojo_Jojo2011-03-19 16:25:18 +00:00Commented Mar 19, 2011 at 16:25
Add a comment
|
4 Answers
If you are using jquery, you can use :
<html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<a href="#foo">foo</a> <a href="#bar">bar</a>
<script>
$('a').click(function () { alert($(this).text()); /* attr('href') */ });
</script>
</html>
Of course the html an so are not good, but the click thing is what you need. Then you could use ajax, or a parameter in the target URL to give the link to the other page.
But why don't you generate that when creating links?
I mean add a href="mylink?from=mylink".
Edit: corrected with your comment. What you need is text() rather than attr('href').
Comments
var link = document.getElementById('link');
link.setAttribute("href", link.getAttribute("href") + "?linkName=" + encodeURI(link.innerHTML));
This will make your link be something like this:
<a id="link" href="http://somewebsite.com?linkName=Name_of_the_link">Name_of_the_link</a>
Then on the "other" page you can access the link name through the GET variable linkName.