I'm trying to click a button programmatically with javascript. Using the following code works fine:
var pbutton= document.getElementById('psubmit');
pbutton.click();
but when I try it on my mobile browser it wont fire the click event. Is their another way to do this for Mobile Browsers?
You will need to implement jquery for this or use a simple javascript.
You can add following code to implement through pure javascript
document.getElementById('psubmit').click();
You can check jsfiddle here
or for jquery you can implement by
$(document).ready(function(){
$('#btn').click(function(){ alert("JQuery Running!");});
$( "#btn" ).trigger( "click" );
});
You can check jsfiddle here
For both this to work you need to have id property defined. And to implement jquery you will need to add jquery file in you code. Hope this helps. Cheers :)
You could use jQuery
$(function(){
$('#psubmit').click()
});
Try using jquery:
$('psubmit').live("click",function(){
//Function code here
});
Related
I have some code I am working on and I cannot seem to figure out the terms to search for assistance.
I am trying to add a jquery statement that executes when the #quickSearchResults_section is clicked "AND" when #nav-input is focused out.
So in a nutshell, I am still learning jquery and programming logic and want to use click function and focusout.
<script>
$(":not(#quickSearchResults_section)").click(function(){
$("#quickSearchResults_section").hide();
});
</script>
Try something like this:
$("#nav-input").on("blur", function(){
$("#quickSearchResults_section").click(function(){
$("#quickSearchResults_section").hide();
});
});
In reference to the site "
http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerClickInput.html
", i used the datePicker() plugin of jquery. But its not working for me!!
I've updated my codings in
http://jsfiddle.net/9L7kE/7/
. Kindly help!!!. Thanks in advance
in js fiddle you have:
$(document).ready(function(){
$(function() {
$( "#date_picker" ).datePicker({clickInput:true});
});
});
$(function_to_tun) is the same as $(document).ready(function_to_tun)
adding a onready event after the event was fired will not not fire it again so you just need to use only one of the 2
$(document).ready(function(){
$( "#date_picker" ).datePicker({clickInput:true});
});
or
$(function() {
$( "#date_picker" ).datePicker({clickInput:true});
});
and also don't forget to add the librarys
Use this one. It's very easy to use.
http://keith-wood.name/datepick.html
I have a jquery mobile page that uses the following code to hide a button when the page is accessed.
$('div:jqmData(role="page")').live('pagebeforeshow',function(){
$("#apply_btn").hide()
});
My problem is that the event only fires when the page is refreshed and not when arriving at the page from somewhere else in the site.
I have tried using the "pageshow" event and the "pageinit" event but it still only fires when the page is refreshed.
Just to remember that live method has been removed from jQuery 1.9. You should use from now on the on method:
$( '#yourPage' ).on( 'pagebeforeshow',function(event){
$("#uniqueButtonId").hide();
});
Have a look at http://jquerymobile.com/demos/1.1.0/docs/api/events.html
This is the syntax:
$( '#yourPage' ).live( 'pagebeforeshow',function(event){
$("#uniqueButtonId").hide();
});
Good Luck
Strangely enough the short version doesn't work for me:
$( '#yourPage' ).on( 'pagebeforeshow',function(event){
$('#uniqueButtonId').hide();
});
but I have to use:
$(document).on( 'pagebeforeshow' , '#yourPage' ,function(event){
$('#uniqueButtonId').hide();
});
try this..
$('div:jqmData(role="page")').live('pagebeforeshow',function(){
$("#apply_btn",context).hide()
});
i'm kinda new to scripting so this might be a bit basic, but i couldn't find an answer anywhere.
To improve my webpage loading time I made some HTML element load (via AJAX) and inserted only when a certain button is clicked, using the jquery .html() function.
That worked, but now all the jquery commands which referred to that element don't seem to apply. I'm guessing it's because the original commands were loaded before the new HTML?
For example, code like this:
$(document).ready(function(){
$('#myButton').click(function(){
$('#placeHolder').html('<div id="touchMe">click me</div>');
});
$('#touchMe').click(function(){
alert ("WORKED");
});
}
How do I make the #touchMe.click command apply to the new incoming HTML?
thanks a lot
Take a look at live()
$('#touchMe').live('click', function() {
Try -
$('#touchMe').live('click',function(){
alert ("WORKED");
});
Instead of
$('#touchMe').click(function(){
alert ("WORKED");
});
use
$('#touchMe').live('click', function(){
alert ("WORKED");
});
you use .live() or .delegate() function instead of click.
$(document).ready(function(){
$('#myButton').live('click', function(){
$('#placeHolder').html('<div id="touchMe">click me</div>');
});
$('#touchMe').live('click', function(){
alert ("WORKED");
});
}
note: the live on "mybutton" is not necessary in this example.
How to use live method with this -> http://www.steamdev.com/zclip/
Edit:
$(document).ready(function(){
$('a#copy-description').zclip({
path:'js/ZeroClipboard.swf',
copy:$('p#description').text()
});
i need to use live method cuz a#copy-description will be generate via javascript.
try to use livequery instead of live. That way you'll be able to bind zclip when it appears in the DOM.
$(document).ready(function(){
$('a#copy-description').livequery(function(){
$(this).zclip({ path:'js/ZeroClipboard.swf', copy:$('p#description').text();
});
});