Reputation: 3342
How can I trigger the following function for a specific DIV
$(document).ready(function() {
if($('div.trigger').length > 0) {
$('div.trigger').click(function() {
if ($(this).hasClass('open')) {
$(this).removeClass('open');
$(this).addClass('close');
$(this).next().slideDown(100);
return false;
} else {
$(this).removeClass('close');
$(this).addClass('open');
$(this).next().slideUp(100);
return false;
}
});
}
});
My html looks like this:
<div class="trigger open"><a href="#"><strong>Dropdown 1</strong></a></div>
<div class="cnt">
<a href="?library&delasset=1">foo</a><br>
<a href="?library&delasset=2">bar</a>
</div>
<div class="trigger open"><a href="#"><strong>Dropdown 2</strong></a></div>
<div class="cnt">
<a href="?library&delasset=3">baz</a><br>
<a href="?library&delasset=4">boo</a>
</div>
My solution was to this:
$(document).ready(function()
{
$('div.trigger:eq(<?=$_GET[exp];?>)').trigger('click');
});
Thanks for the help :)
Upvotes: 0
Views: 243
Reputation: 14390
$('div.trigger:eq(0)').trigger('click');//trigger click event of the Oth element
$('div.trigger:first').trigger('click');//trigger click event of first
$('div.trigger:last').trigger('click');//trigger the click of last one
Upvotes: 2