Languages

Menu
Sites
Language
OnClick event doesnot triggers on app load

We are trying to trigger a click event on a button/link on document.ready function. EXP:

 

$(document).ready(function(){

$('button').trigger('click');

});

 

The above code does not work.

Can you let us know a solution, where we can trigger any event or click on document ready.

Edited by: Brock Boland on 17 Mar, 2014 Reason: Paragraph tags added automatically from tizen_format_fix module.

Responses

6 Replies
Raghavendra Reddy Shiva
Can you try below code ? It worked for me. HTML: Launch Script: $( document ).ready(function() { $('#launch').trigger('click'); }); function clicked() { console.log( " Click triggered !" ); }
Raghavendra Reddy Shiva
Small correction in HTML code: Launch
akshma gandotra
Getting the following error : wgt/index.html (43) :ReferenceError: Can't find variable: $
shovan roy
I tried doing the above steps. I get the console message also appears. The functionality which i want to achieve is still not solved using this steps. I'm writing down the steps of my functionality which I need to do in my web application. 1. There are 2 pages in my app. 2. In the first page I have a link like : -
<a id="launch" data-role="button" href="#mainPage">Launch</a>
3. In the second page, I have the content related to the links. The second page have the id as "mainPage". like:-
<div data-role="page" id="mainPage" data-add-back-btn="true">
<div data-role="header" data-position="fixed">header</div>
<div data-role="content">content area</div>
<div data-role="footer" data-position="fixed" class="footer">footer</div>
</div>
4. On document ready, I need to trigger the click on the anchor button which in-turn will call the second page. FYI, if I do something like window.location.href="#mainPage", then the back button of the page which given by 'data-add-back-btn="true"' is not functional and is not being displayed on the emulator. The solution provided by you is not working. Can you let me know some other solution to this issue.
Marco Buettner
If u use a anchor u have to add any code to click. The link should work if the id was found. Otherwise u can use $.mobile.changePage($('#mainPage')); And 'button' is not valid htmlElement for the selector. Us
$('#launch').on("click", function() {
$.mobile.changePage($('#mainPage');
});
But however... with href="#mainPage" you don't need a js function to change the page.
shovan roy
Thanks Marco for the solution. I have added the above code in the document ready function and triggered the click function of the link on the setTimeout function. However, my code is in anchor tag only with href attribute but when trying to trigger the click of the link it wasn't working. The trigger click event would work perfectly in simulator but not on Emulator.