Last active
July 16, 2018 20:50
-
-
Save kokers/be39abdfde2ed96f11d115491ea32cbe to your computer and use it in GitHub Desktop.
Click doesn't work after AJAX load - jQuery | Example data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.category-item-content { | |
display: none; | |
} | |
/* Demo blog styles */ | |
body{ | |
background:#f5f2f0; | |
padding:1px 15px; | |
font-family:"SF Mono", "Monaco", "Andale Mono", "Lucida Console", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; | |
font-size:14px; | |
} | |
.info-wrapper{ | |
font-size:12px; | |
border-top:1px solid rgba(0,0,0,0.1); | |
padding-top:15px; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h3>Load a category and check if "Expand" still works.<br><small>Hint: It won't</small></h3> | |
<a href="/gh/gist/response.html/be39abdfde2ed96f11d115491ea32cbe/" id="category-nav">Get category via AJAX</a> | |
<div id="category-wrapper"> | |
<h2>Category</h2> | |
<div class="category-item"> | |
<p>This is title <a href="#" class="toggle-item">Expand</a></p> | |
<div class="category-item-content"> | |
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> | |
</div> | |
</div> | |
</div> | |
<p class="info-wrapper">This is an example data to show you the problem. When you first load this page everything works fine. But when you load category via ajax the toggle stops working.</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
/* Ajax navigation */ | |
$('#category-nav').click(function(e) { | |
e.preventDefault(); | |
$('#category-wrapper').load($(this).attr('href')); | |
}); | |
/* Toggle category item */ | |
$('.toggle-item').click(function(e) { | |
e.preventDefault(); | |
$(this).parent().next('.category-item-content').toggle(); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Click doesn't work after AJAX load - jQuery | |
description: This is an example data for | |
authors: | |
- Eliza Witkowska | |
normalize_css: no | |
lang_css: CSS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2>Category From AJAX</h2> | |
<div class="category-item"> | |
<p>This is title in category loaded via AJAX <a href="#" class="toggle-item">Expand</a></p> | |
<div class="category-item-content"> | |
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment