javascript - jquery relative a href="#" remove display block -
<li><a href="#section17"><b>arbeiten</b></a></li>
this link. when click change id of div(#section17) display none block.
<li><a href="#section15"><b>feiern</b></a></li>
now if click on other link(#section15) should change display:block #section17 display:none again , link(#section15) display block
the page doesnt reload url change little bit. can me?
<script type="text/javascript"> $("a").click(function () { var addressvalue = $(this).attr("href"); $(addressvalue).css("display","block"); }); </script>;
demo: http://jsfiddle.net/gvee/qba7e/
html
<ul> <li><a href="#section17"><b>section 17</b></a> </li> <li><a href="#section18"><b>section 18</b></a> </li> <li><a href="#section19"><b>section 19</b></a> </li> </ul> <div id="sections-container"> <div id="section17">section 17</div> <div id="section18">section 18</div> <div id="section19">section 19</div> </div>
jquery
$('a').click(function (e) { // prevent jumping anchor e.preventdefault(); // hide other sections $('#sections-container > div').css('display', 'none'); // show 1 want var addressvalue = $(this).attr('href'); $(addressvalue).css('display', 'block'); });
Comments
Post a Comment