jQuery Articles

Page 39 of 42

How to check if onClick exists on element in jQuery?

ARPIT ANAND
ARPIT ANAND
Updated on 14-Feb-2020 854 Views

These codes might help you −$('body').click(function(){ alert('test' )}) var foo = $.data( $('body').get(0), 'events' ).click // you can query $.data( object, 'events' ) and get an object back, then see what events are attached to it.  $.each( foo, function(i,o) {     alert(i) // guid of the event     alert(o) // the function definition of the event handler });

Read More

What is the difference between $.closest() and $.parents() methods in jQuery?

Amit D
Amit D
Updated on 14-Feb-2020 1K+ Views

The jQuery closest and parents method is used to set or get the first or all ancestor element, matching the selector. Let's see the difference below: jQuery closest() method The closest() method begins with the current element and returns only the first ancestors matching the passed expression. This returned jQuery object has zero or one element. Example You can try to run the following code to learn how to work with jQuery closest method − .myclass * {     display: block;     border: 2px solid blue;     color: red;     padding: 5px;     margin:10px; } ...

Read More

How to get and set form element values with jQuery?

David Meador
David Meador
Updated on 14-Feb-2020 12K+ Views

To get a form value with jQuery, you need to use the val() function. To set a form value with jQuery, you need to use the val() function, but to pass it a new value. Example You can try to run the following code to learn how to get and set form element values with jQuery −                 $(document).ready(function(){              $("#buttonSet").click(function () {          $("#txtBox").val("Amit");          $("input:radio").val(["male"]);          $("#buttonGet").removeAttr('disabled');       });        $("#buttonGet").click(function () {         $("#result").html(           $("#txtBox").val() + "<br/>" +           $("input:radio[name=rd]:checked").val()         );       });      });              Name            Gender     Male     Female                   

Read More

How to get the closest input value from clicked element with jQuery?

David Meador
David Meador
Updated on 14-Feb-2020 9K+ Views

To get the closest input value from clicked element with jQuery, follow the steps − You need to use closest to find the closest ancestor matching the given. Now, find the input with the given name using the attribute equals selector. The last step is to use val() metjod to retrieve the value of the input. Let's first see how to add jQuery − Example You can try to run the following code to get closest input value from clicked element with jQuery −                    $(document).ready(function(){         $(".add").on("click", function () {           var v = $(this).closest("div.content").find("input[name='rank']").val(); ...

Read More

What is the difference between text() and html() in jQuery?

David Meador
David Meador
Updated on 14-Feb-2020 584 Views

jQuery comes with a lot of methods to manipulate attributes. These are DOM related methods. The attributes include, text() and html() too, text() – This method sets or returns the text content of elements selected. html() – This method sets or returns the content of elements selected. Example You can try to run the following code to learn how to manipulate attributes with text() and html() methods − $(document).ready(function(){   $("#button1").click(function(){     alert("Using text()- " + $("#demo").text());   });   $("#button2").click(function(){     alert("Using html()- " + $("#demo").html());   }); }); This is demo text. Text HTML

Read More

How to get innerHTML of a div tag using jQuery?

Ricky Barnes
Ricky Barnes
Updated on 14-Feb-2020 4K+ Views

To get the innerHTML of a div tag in jQuery, use the class with innerHTML. You can try to run the following code to learn how to get innerHTML of a div tag using jQuery −ExampleLive Demo  $(document).ready(function(){    $("#button1").click(function(){      var one = $('.a').innerHTML;      alert(one);    });  });    Value one    Get

Read More

How to call a jQuery plugin function outside the plugin?

Amit D
Amit D
Updated on 12-Feb-2020 490 Views

jQuery is a JavaScript library introduced to make development with JavaScript easier. It reduces the development time. Let us see how to call a jQuery plugin function outside the plugin.For calling, wrap the jQuery method for returning the instance of the constructor. Call prototype methods on it.example$.fn.myFunction = function(config){     return new myFunction (config); };Instance the plugin and call the method −var plugin = $('#someSelector').myFunction(); plugin.setToken(column);

Read More

How to use FastClick with jQuery Mobile the right way in HTML?

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 30-Jan-2020 202 Views

There is no need to use 3rd party plugins like Fastclick. jQuery Mobile solved this with vclick event.JQuery works well on mobile and desktop and don’t have 300 ms delay$(document).on('vclick', '#impButton', function(){ });

Read More

Effects and animations with Google Maps markers in HTML5

Samual Sam
Samual Sam
Updated on 30-Jan-2020 291 Views

There is no way to fade markers through API.However, markers can be simulated by creating Custom Overlay.Custom overlay usually contains a div with the help of which opacity can be controlled by javascript or jquery.In order to create effects or animations over Google Maps markers, we need a custom overlay.The marker can be added to map and it surely makes optimized: false optionvar newmarkerimg= $('#map_canvas img[src*="iconmarker "][class!="imageadjust "]');

Read More

jQuery Mobile: Sending data from one page to the another

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 29-Jan-2020 237 Views

To pass values, let us say our is the following, with page new.html,StructureThe JS will be:$( document ).on( "pageinit", "#new", function( event ) {    var myParam = $(this).data("url").split("?")[1];    myParam = parameters.replace("structure=","");    alert(myParam); });

Read More
Showing 381–390 of 413 articles
Advertisements