devel:jqueryfaq
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
devel:jqueryfaq [2014-01-13 12:56] – [How do I know if I need to adjust my plugin?] updated hh lohmann | devel:jqueryfaq [2023-10-19 23:28] – [getElementsByClass()] Klap-in | ||
---|---|---|---|
Line 7: | Line 7: | ||
===== Why did you switch to jQuery? ===== | ===== Why did you switch to jQuery? ===== | ||
- | jQuery is a well known, widely used and tested library. It is well [[http:// | + | jQuery is a well known, widely used and tested library. It is well [[http:// |
===== What jQuery version is supported? ===== | ===== What jQuery version is supported? ===== | ||
Line 31: | Line 31: | ||
// | // | ||
- | :!: It is always recommended to create a dedicated testing environment, | ||
===== What are the most commonly used JS features that are now deprecated? ===== | ===== What are the most commonly used JS features that are now deprecated? ===== | ||
- | Here are the 4 most commonly used, deprecated bits from our old library and some simple examples how to replace them with jQuery features. | + | Here are the most commonly used, deprecated bits from our old library and some simple examples how to replace them with jQuery features. |
- | **'' | + | ==== $('...') ==== |
- | Note that '' | + | as a shortcut to '' |
+ | |||
+ | * Note that '' | ||
<code javascript> | <code javascript> | ||
Line 52: | Line 53: | ||
</ | </ | ||
- | **'' | + | ==== getElementsByClass() ==== |
+ | |||
+ | use jQuery' | ||
<code javascript> | <code javascript> | ||
Line 58: | Line 61: | ||
var htmlelements = getElementsByClass( ' | var htmlelements = getElementsByClass( ' | ||
// htmlelements now is an array of DOM elements | // htmlelements now is an array of DOM elements | ||
- | for( var n in htmlelements ) { | + | for(var n in htmlelements ) { |
dosomething( htmlelements[n] ); | dosomething( htmlelements[n] ); | ||
} | } | ||
/* New code */ | /* New code */ | ||
- | jQuery(' | + | jQuery(' |
+ | | ||
+ | }); | ||
/* Or, this new code */ | /* Or, this new code */ | ||
- | var jqueryelements = jQuery(' | + | let $jqueryelements = jQuery(' |
- | // jqueryelements is a jquery thing : an array plus some other stuff. | + | // $jqueryelements is a jquery thing: an array plus some other stuff. |
- | jqueryelements.each(function(){dosomething(this); | + | $jqueryelements.each(function(){ |
+ | | ||
+ | }); | ||
/* or, if you prefer (I don't know wich one is better) */ | /* or, if you prefer (I don't know wich one is better) */ | ||
- | for ( var n = 0; n < jqueryelements.length; | + | for (let n = 0; n < $jqueryelements.length; |
- | dosomething(jqueryelements[n]); | + | dosomething($jqueryelements[n]); |
} | } | ||
</ | </ | ||
- | **'' | + | |
+ | ==== addInitEvent() | ||
+ | |||
+ | registering | ||
<code javascript> | <code javascript> | ||
Line 89: | Line 99: | ||
</ | </ | ||
- | **'' | + | ==== addEvent() |
+ | |||
+ | Registering | ||
<code javascript> | <code javascript> | ||
/* Old code */ | /* Old code */ | ||
- | addEvent(obj, | + | addEvent(obj, |
+ | alert(" | ||
+ | }); | ||
+ | |||
+ | /* Recenter old code */ | ||
+ | jQuery(obj).click(function(){ | ||
+ | | ||
+ | }); | ||
/* New code */ | /* New code */ | ||
- | jQuery(obj).EVENT(function(){ alert(" | + | jQuery(obj).on(" |
+ | | ||
+ | }); | ||
</ | </ | ||
- | * => replace | + | * replace " |
+ | |||
+ | ==== tw_sack ==== | ||
- | **'' | + | executing AJAX requests - use jQuery' |
<code javascript> | <code javascript> | ||
Line 140: | Line 163: | ||
- | For example, if you want to use the [[http:// | + | For example, if you want to use the [[http:// |
<code javascript> | <code javascript> |
devel/jqueryfaq.txt · Last modified: 2023-10-19 23:36 by Klap-in