.is( selector ) .is( function(index) ) .is( jQuery object ) .is( element )
<html> <head> <title>ThaiCreate.Com jQuery Tutorials</title> <style> div { width:60px; height:60px; margin:5px; float:left; border:4px outset; background:green; text-align:center; font-weight:bolder; cursor:pointer; } .blue { background:blue; } .red { background:red; } span { color:white; font-size:16px; } p { color:red; font-weight:bolder; background:yellow; margin:3px; clear:left; display:none; } </style> <script type="text/javascript" src="jquery-1.6.4.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("div").one('click', function () { if ($(this).is(":first-child")) { $("p").text("It's the first div."); } else if ($(this).is(".blue,.red")) { $("p").text("It's a blue or red div."); } else if ($(this).is(":contains('Peter')")) { $("p").text("It's Peter!"); } else { $("p").html("It's nothing <em>special</em>."); } $("p").hide().slideDown("slow"); $(this).css({"border-style": "inset", cursor:"default"}); }); }); </script> </head> <body> <div></div> <div class="blue"></div> <div></div> <div class="red"></div> <div><br/><span>Peter</span></div> <div class="blue"></div> <p> </p> </body> </html>
<html> <head> <title>ThaiCreate.Com jQuery Tutorials</title> <style> div { color:red; } </style> <script type="text/javascript" src="jquery-1.6.4.js"></script> <script type="text/javascript"> $(document).ready(function(){ var isFormParent = $("input[type='checkbox']").parent().is("form"); $("div").text("isFormParent = " + isFormParent); }); </script> </head> <body> <form> <input type="checkbox" /> </form> <div></div> </body> </html>
<html> <head> <title>ThaiCreate.Com jQuery Tutorials</title> <style> div { color:red; } </style> <script type="text/javascript" src="jquery-1.6.4.js"></script> <script type="text/javascript"> $(document).ready(function(){ var isFormParent = $("input[type='checkbox']").parent().is("form"); $("div").text("isFormParent = " + isFormParent); }); </script> </head> <body> <form> <p><input type="checkbox" /></p> </form> <div></div> </body> </html>
<html> <head> <title>ThaiCreate.Com jQuery Tutorials</title> <style> li { cursor:pointer; } </style> <script type="text/javascript" src="jquery-1.6.4.js"></script> <script type="text/javascript"> $(document).ready(function(){ var $alt = $("#browsers li:nth-child(2n)").css("background", "#00FFFF"); $('li').click(function() { var $li = $(this); if ( $li.is( $alt ) ) { $li.slideUp(); } else { $li.css("background", "red"); } }); }); </script> </head> <body> <ul id="browsers"> <li>Chrome</li> <li>Safari</li> <li>Firefox</li> <li>Opera</li> </ul> </body> </html>
<html> <head> <title>ThaiCreate.Com jQuery Tutorials</title> <style> li { cursor:pointer; } </style> <script type="text/javascript" src="jquery-1.6.4.js"></script> <script type="text/javascript"> $(document).ready(function(){ var $alt = $("#browsers li:nth-child(2n)").css("background", "#00FFFF"); $('li').click(function() { if ( $alt.is( this ) ) { $(this).slideUp(); } else { $(this).css("background", "red"); } }); }); </script> </head> <body> <ul id="browsers"> <li>Chrome</li> <li>Safari</li> <li>Firefox</li> <li>Opera</li> </ul> </body> </html>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท