Reputation: 193
I am using a store locator jquery plugin from http://www.bjornblog.com/web/jquery-store-locator-plugin for my website and everything works fine but what I want to add is once the store location list is generated, the first one on the list is automatically clicked.
In the Jquery, I can see there is a section controlling the click on the list. It has some parameters.
// Handle clicks from the list
$(document).on('click.'+pluginName, '.' + _this.settings.locationList + ' li', function () {
//do the work.
}
The pluginName is 'storelocator' and _this.settings.locationList is 'bh-sl-loc-list'
the elements of the list shown on the html
<div class="bh-sl-loc-list">
<ul class="list list-unstyled"></ul>
<li></li>
<li></li>
<li></li>
</div>
I tried the belows but obviously nothing worked, what sort of syntax I should use to maybe pass the parameters and call it? Much appreciated.
document.getElementById(".bh-sl-loc-list:first-child").onclick();
$('.bh-sl-loc-list:first-child').trigger('click');
Upvotes: 0
Views: 209
Reputation: 581
It seems that you want to trigger the event bind on the element li.
Maybe you could try it like this:
$('.bh-sl-loc-list li:first-child').trigger('click.pluginName');
Or:
$('.bh-sl-loc-list ul li:first-child').trigger('click.pluginName');
Upvotes: 1
Reputation: 1962
Try this :
document.getElementById("bh-sl-loc-list:first-child").click();
Upvotes: 0
Reputation: 15846
$(document).on('click' , pluginName, '.' + _this.settings.locationList + ' li', function () {
//do the work.
}
Upvotes: 0
Reputation: 781004
The event binding has a namespace, you need to include that in your trigger
call.
$('.bh-sl-loc-list:first-child').trigger('click.pluginName');
Replace pluginName
with the actual name of the plugin (whatever is in its internal variable pluginName
).
Upvotes: 1