Syntax
โค้ด: เลือกทั้งหมด
jQuery(':text')
โค้ด: เลือกทั้งหมด
<html>
<head>
<style>
textarea { height:25px; }
</style>
<script type="text/javascript" src="jquery-1.6.4.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var input = $("form input:text").css({background:"yellow", border:"3px red solid"});
$("div").text("For this type jQuery found " + input.length + ".")
.css("color", "red");
$("form").submit(function () { return false; }); // so it won't submit
});
</script>
</head>
<body>
<form>
<input type="button" value="Input Button"/>
<input type="checkbox" />
<input type="file" />
<input type="hidden" />
<input type="image" />
<input type="password" />
<input type="radio" />
<input type="reset" />
<input type="submit" />
<input type="text" />
<select><option>Option</option></select>
<textarea></textarea>
<button>Button</button>
</form>
<div>
</div>
</body>
</html>
จากตัวอย่างเป็นการใช้ Selectors กับ :text Selector() ในการอ้างถึง element var input = $("form input:text") ที่มี input type="text" มีการกำหนด .css({background:"yellow", border:"3px red solid"}); จะมีผลแค่ <input type="text" />