greasypigstudios
Member
Posted 2 years ago #
Hello all,
I'm developing a site for a client and what he wants requires all links in the posts to have javascript attached to it automatically.
It goes something like this. Let's say in the post he creates a link with the name of LINKNAME. Here's what needs to happen automatically:
<a href="URL" onMouseOver="setReadOut(LINKNAME)">LINKNAME</a>
Where the javascript gets added automatically when he publishes the page and the LINKNAME becomes a variable passed to the javascript.
Any takers?
ianatkins
Member
Posted 2 years ago #
Jquery would be perfect, if your not familiar with it check it out.
<script type="text/javascript">
$(document).ready(function() { // run when the document is loaded
$("a").click(function () { // bind a click function to all links
linkname = $(this).val(); // get the link name
setReadOut(linkname); // run your function
});
});
</script>
jquery.com
greasypigstudios
Member
Posted 2 years ago #
quick question on this:
First, I modified it to .mouseenter instead of .click
Secondly, setReadOut() needs to take strings enclosed in ' ' so it would have to return a function like setReadOut('link name')
It seems to not be working for this?
greasypigstudios
Member
Posted 2 years ago #
So i just tested and with hyperlinks and instead of
linkname = $(this).val();
should be
linkname = $(this).text();
To take the text of the hyperlink.