I am making a menu where on rollover, the text of the link changes (fades in). I just copied and pasted a block of code off another thread
<script type="text/javascript">
function fade_new_text(){
$('#what').animate({'opacity': 0}, 500, function () {
$(this).text('new text');
}).animate({'opacity': 1}, 500);
}
function revert(){
$('#what').animate({'opacity': 0}, 500, function () {
$(this).text('do something');
}).animate({'opacity': 1}, 500);
}
</script>
then in the body section I have the menu itself
<body>
<a href="#" id="what" onmouseover="fade_new_text();" onmouseout="revert();">Do something</a>
</body>
This works well with one link, but I need to create 7 of them and hopefully reuse this code in the future. So I need to pass both the link id and the new text to Jquery function for 6 other links, hopefully from ‘onmouseover’ and ‘onmouseout’, as it would make the most sense? I am completely new to Jquery, and would appreciate your advice on how to do that.
The test file is at http://www.voxcommunications.ca/test.html
Working off of Bryans answer, this way prevents recurring animations when unnecessary, also adds the data-mouseout dynamically instead of rewriting the Link Text in the data-mouseout on each link.
Here is a working Example FIDDLE
HTML
JQuery