0

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');
0

4 Answers 4

1

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');
Sign up to request clarification or add additional context in comments.

6 Comments

didn't work, I am frustrated. I suspect $('.bh-sl-loc-list li:first-child').trigger('click.pluginName'); is very close. I did if a condition it did return first li, but just cant click on it...
I have tried $('.bh-sl-loc-list li:first-child').trigger('click.storeLocator'); at one of the lib's example and it works well.
I guess in your situation maybe the trigger occur before the list's event has been bind.
Hi Li xiaojun, thanks a lot!!! i put it in a wrong place. I tried directly after the document()... and it worked!!! save my day!
just curious anyway, where did you add the line of code?
|
1

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).

1 Comment

I tried but didn't work, $(function() { $('#map-container').storeLocator({ 'dataType': 'json', 'dataLocation': '../wp-content/themes/subway-clone/data/locations.json' }); $('.bh-sl-loc-list:first-child').trigger('click.storelocator'); });
0
$(document).on('click' , pluginName, '.' + _this.settings.locationList + ' li', function () {
//do the work.
}

Comments

0

Try this :

document.getElementById("bh-sl-loc-list:first-child").click();

1 Comment

I did and no reply :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.