Sajjad Sajjad - 4 months ago 22
HTML Question

How to use same JQuery method for elements having different Ids?


<script src=" "></script>
<script src="myjquery.js"></script>
<a id='mylink1' href='#'>Click to Display First div</a> <br>
<div id='mydv1' style='display: none;' > I am First div</div>

<a id='mylink2' href='#'>Click to Display Second div</a> <br>
<div id='mydv2' style='display: none;' > I am Second div</div>

myjquery.js file is:


return false;

Actually I dont want to write two separate Jquery methods

But using the single Jquery method like above i.e.
causes to display both divs, even by clicking on only one hyperlink.

What correction is needed in above Jquery method so that clicking on a hyperlink displays only corresponding div.


Html code

<input type='button' id='mylink1'/>
<div id='mydv1' style='display:none'>
I am first div
<input type='button' id='mylink2'/>
<div id='mydv2' style='display:none'>
I am second div

Jquery Code

     var Id='#mydv'+str.slice(str.indexOf('vish'),str.length)
     return false;

Fiddle Ex here