Filed under jquery

jquery plugin to prevent double submission of button

// jQuery plugin to prevent double submission of forms jQuery.fn.preventDoubleSubmission = function() { $(this).bind(‘submit’,function(e){ var $form = $(this); if ($form.data(‘submitted’) === true) { // Previously submitted – don’t submit again e.preventDefault(); } else { // Mark it so that the next submit can be ignored $form.data(‘submitted’, true); } }); // Keep chainability return this; }; … Continue reading

jQuery selector

Note that since JavaScript arrays use 0-based indexing, these selectors reflect that fact. This is why$(‘.myclass:lt(1)’) selects the first element in the document with the class myclass, rather than selecting no elements. In contrast, :nth-child(n) uses 1-based indexing to conform to the CSS specification.

jquery selection condition

<!DOCTYPE html> <html> <head> <script src=”http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js”></script&gt; <meta charset=utf-8 /> <title>JS Bin</title> </head> <body> <div id=”myparent”> <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> <li>7</li> </ul> </div> <div id=”another_thing”> <ol> <li>one</li> <li>two</li> </ol> </div> </body> </html> jQuery( function ($) { $(“li”).filter(“[class*=c]”).css(“color”, “red”); $(“li”).filter( function (i) {return i!=5;} ).css(“color”, “red”); } ); jQuery( function ($) { jq = … Continue reading

jquery

<script type=”text/javascript”> $(document).ready(function() { var jq = $(‘label’); jq.slice(0, 2).css(“border”, “thick double black”); jq.slice(4).css(“border”, “thick solid red”); }); </script> …

jQuery method chaining

$(‘label’).css(“color”, “blue”).add(“input[name!=’rose’]”).filter(“[for!=’snowdrop’]”) The filter method removes all of the elements in a jQuery object that don’t meet a specified condition. I explain this method in more depth in Chapter 6, but for the moment it is enough to know that this allows me to remove any element from the jQuery object that has a for … Continue reading