asp.net mvc 4 - change the content of div with another div- jquery -
my requirement: have 3 different <div>
s. when user click first link, first <div>
data should display. when click second link, display second <div>
data @ position of first <div>
.
code:
<div id="firstdiv" > //first div data </div> <div id="seconddiv"> //second div data </div> <div id="lastdiv"> //last div data </div> <ul class="footer_links"> <li><a href="#" id="firstlink"></li> <li><a href="#" id="secondlink"></li> <li><a href="#" id="lastlink"></li> </ul>
here when user click firstlink
need display fistdiv
data , when user click secondlink
need display seconddiv
data @ position of firstdiv
.
for have done jquery, not proper way.
$(document).ready(function () { $("#firstdiv").replacewith($('#seconddiv')); $('#seconddiv').attr('id', 'firstdiv'); });
here have done firstdiv
replacing seconddiv
, changing id firstdiv
.
displaying data @ position of first <div>
. display forward only. not backward. because here replacing firstdiv
seconddiv
. not proper way. can 1 tell this. how can forward , backward.
if change html following:
<div id="firstdiv" class="datadiv"> //first div data </div> <div id="seconddiv" class="datadiv"> //second div data </div> <div id="lastdiv" class="datadiv"> //last div data </div> <ul class="footer_links"> <li><a href="#firstdiv" id="firstlink" class="link">first</a></li> <li><a href="#seconddiv" id="secondlink" class="link">second</a></li> <li><a href="#lastdiv" id="lastlink" class="link">third</a></li> </ul>
you can use following jquery:
var divs = $('.datadiv'); $('.link').click(function(e) { e.preventdefault(); divs.hide(); $($(this).attr('href')).show(); });
Comments
Post a Comment