Pass a DIV ID to a self-defined function in JQuery
Hi all,
I am writing a simple html in which when the user moves his mouse over a particular DIV,
a message box will pop up.
Part of the code is as follows:
- <DIV id="1">Hide them</DIV>
- <p>Hiya</p>
- <p>Such interesting text, eh?</p>
- </td></tr></table>
- <script>
- $("#1").mouseover(function () {
- $("p").hide("slow");
- })
- $("#1").mouseout(function () {
- $("p").show("slow");
- })
- </script>
I want to make the code re-useable, but dont know how to modify it.
Let's think the case that there are a few more links in the HTMl file,
and then I got to write the same script again.
How is it to modify the script above to do the same result as the following example:
- <DIV id="1" onClick="function(this.value)">Hide them</DIV>
- <p>Hiya</p>
- <p>Such interesting text, eh?</p>
- </td></tr></table>
- <script>
- function(divID){
- if(divID){
- divID.mouseover.show();
- else
- divID.mouseout.hide();
- }
- }
- </script>
I dont know how to pass a DIV's ID to a self-defined function in JQuery.
Could you help me out please?