In: JavaScript
7 Jul 2010Replace getElementById JavaScript function by using jQuery selector. Your old getElementById code: document.getElementById(’unique_id’).doSomething(); Your new jQuery code: jQuery(’#unique_id’).doSomething();
In: JavaScript
7 Jul 2010Use jQuery one to attach event that will be executed only once. 1 2 3 <a id="jQueryOne" href="javascript:void(0);" title="jQuery one"> Tell me once! </a> 1 2 3 jQuery(’#jQueryOne’).one(’click’, function() { alert(’jQuery one: "I shall say this only once".’); });
In: JavaScript
6 Jul 2010To load jQuery from Google, use following snippet: <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
In: JavaScript
6 Jul 2010You can use jQuery function load() to load external page. Therefore, you can easily make dynamically loaded content on your website. Let’s say you want to load page “content.php” into div on your page. A whole page would contain next snippet: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 [...]
In: JavaScript|PHP
6 Jul 2010In order to lower down number of http requests and speed up your website, you can use regular JS include, to include PHP file. <link rel="javascript" type="text/javascript" href="alljs.php"> PHP JS include file This is how PHP file, that includes all JS files you want to be included, should look on your server: 1 2 3 [...]
In: JavaScript
1 Jul 2010To add class to HTML element using jQuery, you should be using jQuery function addClass(). By using a selector to match elements on HTML and calling function .addClass(‘className’); you can add class to the specific element. See example: 1 jQuery(’#element_id’).addClass(’className’);
In: JavaScript
30 Jun 2010You can submit form using jQuery easily using .submit() jQuery function, just like in this snippet: jQuery(’#form_id’).submit();
In: JavaScript
30 Jun 2010You can use jQuery focus on element in order to set focus upon element or in order to check if there is focus on element? In order to set focus on element use: 1 jQuery(’#element_id’).focus(); In order to check if there is focus on element use: 1 2 3 if(jQuery(’#element_id’).is(":focus")) { //fixed thanks to [jquery [...]
In: JavaScript
29 Jun 2010If you want to find specific tag with jQuery you can use jQuery selector. Let’s say you would like to find all div elements with class=”handle”, and you would like to remove them. Example shows how: jQuery(’div[class=handle]‘).remove();