Size: 2283
Comment:
|
Size: 2488
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
## page was renamed from jquery | |
Line 2: | Line 3: |
The purpose of jQuery is to make it much easier to use JavaScript on your website. | The purpose of jQuery is to make it much easier to use [[Javascript]] on your website. |
Line 86: | Line 87: |
return "#" + myid.replace( /(:|\.|\[|\])/g, "\\$1" ); | return "#" + myid.replace( /(:|\.|\[|\])/g, "\\$1" ); |
Line 89: | Line 90: |
== Ajax error handler == {{{#!highlight javascript function onError(xhr, status, error){ console.log(xhr.responseText); // text returned on error } }}} |
jquery
The purpose of jQuery is to make it much easier to use Javascript on your website.
DOM ready
Find element by id
Toggle line numbers
1 // element id id1234
2 var x1234 = $("#id1234");
Find elements by class
Get or set select dropdownlist selected value
Toggle line numbers
1 $("#dropdown").val(); //get value
2 $("#dropdown").val('asd'); //select value asd
3
.attr( attributeName )
Returns String Get the value of an attribute for the first element in the set of matched elements.
.text()
Returns String Get the combined text contents of each element in the set of matched elements, including their descendants.
html()
Returns String Get the HTML contents of the first element in the set of matched elements.
.append( content [, content ] )
Returns jQuery Insert content, specified by the parameter, to the end of each element in the set of matched elements.
.empty()
Returns jQuery Remove all child nodes of the set of matched elements from the DOM.
jQuery.get( url [, data ] [, success ] [, dataType ] )
Returns jqXHR Load data from the server using a HTTP GET request.
Toggle line numbers
1 $.get( "test.cgi", { name: "John", time: "2pm" } )
2 .done( function( data ) {
3 alert( "Data Loaded: " + data );
4 });
5
6 $.ajax({
7 url: url,
8 data: data,
9 success: success, // function(data, textStatus,jqXHR )
10 error: error , // function( jqXHR, textStatus, errorThrown )
11 dataType: dataType // text, html, xml, json, jsonp, and script.
12 });
Select element with . and : in id
Toggle line numbers
1 function jq( myid ) {
2 return "#" + myid.replace( /(:|\.|\[|\])/g, "\\$1" );
3 }
Ajax error handler
Toggle line numbers
1 function onError(xhr, status, error){
2 console.log(xhr.responseText); // text returned on error
3 }