Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
23
rated 0 times [  27] [ 4]  / answers: 1 / hits: 27523  / 8 Years ago, sat, april 30, 2016, 12:00:00

i have a div that is hidden by default when i click on the link then the div is shown. for e.g



<a href=#expe1 class=fa fa fa-times closer ></a> //this is the link
<div class=resume id=expe1></div> // this div is hidden by default


here is the jquery part



jQuery(document).ready(function($) {
$('a[href^=#]').on('click', function(event) {

var target = $( $(this).attr('href') );

target.show();
if( target.length ) {
event.preventDefault();
$('html, body').animate({
scrollTop: target.offset().top
}, 2000);
}

});
});


Now i want to hide that div which i showed
So i created another link in front of that div



<div class=resume id=expe1></div><a href=#expe1>x</a>


and here is jquery code



jQuery(document).ready(function($) {
$('a[href^=#]').on('click', function(event) {

var target = $( $(this).attr('href') );
target.hide();
});
});


but this doesn't works as first jquery shown above is processed first then the last one.. is there any better way to hide that div becuase i have many div like this


More From » jquery

 Answers
4

Codepen Demo



<a href=#expe1 class=fa fa fa-times closer >Link1</a>  
<div class=resume id=expe1>Open Block 1</div>

<a href=#expe2 class=fa fa fa-times closer >Link2</a>
<div class=resume id=expe2>Open Block 2</div>

<a href=#expe3 class=fa fa fa-times closer >Link3</a>
<div class=resume id=expe3>Open Block 3</div>


JS:



 $('.resume') .hide()
$('a[href^=#]').on('click', function(event) {
$('.resume') .hide()
var target = $(this).attr('href');

$('.resume'+target).toggle();

});

[#62349] Wednesday, April 27, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
neilshamarh

Total Points: 181
Total Questions: 94
Total Answers: 104

Location: Guadeloupe
Member since Sat, Aug 22, 2020
4 Years ago
;