Thursday, November 15, 2012

Jquery javascript Collapse using $this

I\’ve got four divs that toggle by their title (as you can see below I showed one set). Each title link class matches the class before the text field class. Instead of writing the javascipt four seperate times I was hoping to write something dryer using $this to target the current class, and then the current class the class text.


The important_info_header class will be a dynamic class for each div.


Not that great with this kind of writing so any help is welcome


Failed ATTEMPT



$(this).click(function() {
$(this+\'.text\').slideToggle(\'slow\', function() {
//ani complete.

});
});


Working Markup


HTML START



<h4><a href=\"javascript:void(0)\" class=\"important_info_header\"><%= t(\"catalog_items.show_lot.important_info_header\")%></a></h4>
<div class=\"important_info_header text\">
<p><%= t(\"catalog_items.show_lot.important_info\") %></p>
</div><!-- /text -->


<h4><a href=\"javascript:void(0)\" class=\"important_info_header\"><%= t(\"catalog_items.show_lot.important_info_header\")%></a></h4>
<div class=\"important_info_header text\">
<p><%= t(\"catalog_items.show_lot.important_info\") %></p>
</div><!-- /text -->



<h4><a href=\"javascript:void(0)\" class=\"rules\"><%= t(\"catalog_items.show_lot.important_info_header\")%></a></h4>
<div class=\"rules text\">
<p><%= t(\"catalog_items.show_lot.important_info\") %></p>
</div><!-- /text -->


<h4><a href=\"javascript:void(0)\" class=\"shipping\"><%= t(\"catalog_items.show_lot.important_info_header\")%></a></h4>
<div class=\"shipping text\">
<p><%= t(\"catalog_items.show_lot.important_info\") %></p>
</div><!-- /text -->


HTML END



$(\'.important_info_header\').click(function() {
$(\'.important_info_header.text\').slideToggle(\'slow\', function() {
//ani complete.

});
});






Rating: 3 out of 5 based on 3 ratings



The post Jquery javascript Collapse using $this appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/jquery-javascript-collapse-using-this.html

No comments:

Post a Comment