var tables = document.getElementsByTagName("table");
for (var t = 0; t<tables.length; t++) {
var rows = tables[t].getElementsByTagName("tr");
for (var i = 0; i<rows.length; i += 2) {
if (!/(^|\s)even(\s|$)/.test(rows[i].className)) {
rows[i].className += " even";
}
}
}
jQuery("table tr:nth-child(even)").addClass("even");
jQuery("table tr:nth-child(even)").addClass("even");
JQuery Function
jQuery("table tr:nth-child(even)").addClass("even");
JQuery Function
JQuery Selector (CSS Expression)
jQuery("table tr:nth-child(even)").addClass("even");
JQuery Function
JQuery Selector (CSS Expression)
JQuery Method
<!DOCTYPE html>
<html>
<body>
<ul>
<li><a>home</a></li>
<li><a>about</a></li>
</ul>
</body>
</html>
<html>
<body>
<ul>
<li><a>home</a></li>
<li><a>about</a></li>
</ul>
<script src="jquery.js"></script>
<script>
jQuery("ul");
</script>
</body>
</html>
<html>
<body>
<ul id="nav">
<li><a>home</a></li>
<li><a>about</a></li>
</ul>
<script src="jquery.js"></script>
<script>
jQuery("ul").attr("id", "nav");
</script>
</body>
</html>
<html>
<body>
<ul id="nav">
<li><a>home</a>;</li>
<li><a>about</a></li>
</ul>
<script src="jquery.js"></script>
<script>
jQuery("#nav a");
</script>
</body>
</html>
<html>
<body>
<ul id="nav">
<li><a href="/home">home</a></li>
<li><a href="/about">about</a></li>
</ul>
<script src="jquery.js"></script>
<script>
jQuery("#nav a").each(function(){
jQuery(this).attr("href", "/" + jQuery(this).text());
});
</script>
</body>
</html>
<html>
<body>
<ul id="nav">
</ul>
</body>
</html>
<html>
<body>
<ul id="nav">
</ul>
<script src="jquery.js"></script>
<script>
jQuery("<li>home</li>");
jQuery("<li>about</li>");
</script>
</body>
</html>
<html>
<body>
<ul id="nav">
</ul>
<script src="jquery.js"></script>
<script>
jQuery("<li>home</li>").wrapInner("a");
jQuery("<li>about</li>").wrapInner("a");
</script>
</body>
</html>
<html>
<body>
<ul id="nav">
<li><a>home</a></li>
<li><a>about</a></li>
</ul>
<script src="jquery.js"></script>
<script>
jQuery("<li>home</li>").wrapInner("a").appendTo("#nav");
jQuery("<li>about</li>").wrapInner("a").appendTo("#nav");
</script>
</body>
</html>
$(document).ready()
<head>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$( document ).ready(function() {
$( "p" ).text( "The DOM is now loaded and can be manipulated." );
});
</script>
</head>
<body>
<p>Not loaded yet.</p>
</body>
$(document).ready(function() {...} ) ==
$(function() {...})
$.noConflict()
<script src="other_lib.js"></script>
<script src="jquery.js"></script>
<script>
$.noConflict();
jQuery( document ).ready(function( $ ) {
// Code that uses jQuery's $ can follow here.
});
// Code that uses other library's $ can follow here.
</script>
$.noConflict()
<script src="other_lib.js"></script>
<script src="jquery.js"></script>
<script>
jq2 = jQuery.noConflict();
jq2(function( $ ) {
// Code using $ as usual goes here;
// the actual jQuery object is jq2
});
// Code that uses other library's $ can follow here.
</script>
var req = $.get( "http://example.com/api/users", function() {
alert( "success" );
})
.done(function() {
alert( "second success" );
})
.fail(function() {
alert( "error" );
})
.always(function() {
alert( "finished" );
});
$.ajax({
url: 'http://example.com/api/users',
data: {
format: 'json'
},
error: function() {
//handle the error here
},
dataType: 'jsonp',
success: function(data) {
//data is the response. Handle it accordingly here
},
type: 'GET'
});