.find( selector ) .find( jQuery object ) .find( element )
<html> <head> <title>ThaiCreate.Com jQuery Tutorials</title> <script type="text/javascript" src="jquery-1.6.4.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("p").find("span").css('color','red'); }); </script> </head> <body> <p><span>Hello</span>, how are you?</p> <p>Me? I'm <span>good</span>.</p> </body> </html>
<html> <head> <title>ThaiCreate.Com jQuery Tutorials</title> <style> span { color: blue; } </style> <script type="text/javascript" src="jquery-1.6.4.js"></script> <script type="text/javascript"> $(document).ready(function(){ var $spans = $('span'); $("p").find( $spans ).css('color','red'); }); </script> </head> <body> <p><span>Hello</span>, how are you?</p> <p>Me? I'm <span>good</span>.</p> <div>Did you <span>eat</span> yet?</div> </body> </html>
<html> <head> <title>ThaiCreate.Com jQuery Tutorials</title> <style> p { font-size:20px; width:200px; cursor:default; color:blue; font-weight:bold; margin:0 10px; } .hilite { background:yellow; } </style> <script type="text/javascript" src="jquery-1.6.4.js"></script> <script type="text/javascript"> $(document).ready(function(){ var newText = $("p").text().split(" ").join("</span> <span>"); newText = "<span>" + newText + "</span>"; $("p").html( newText ) .find('span') .hover(function() { $(this).addClass("hilite"); }, function() { $(this).removeClass("hilite"); }) .end() .find(":contains('t')") .css({"font-style":"italic", "font-weight":"bolder"}); }); </script> </head> <body> <p> When the day is short find that which matters to you or stop believing </p> </body> </html>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท