jQuery selectors , html elements গুলিকে গ্রুপ বা পৃথক হিসাবে সিলেক্ট করতে কাজে লাগে।
jQuery Element Selectors
jQuery uses CSS selectors to select HTML elements.
$(“p”) selects all <p> elements.
$(“p.intro”) selects all <p> elements with.
$(“p#demo”) selects the first <p> element with id=”demo”.
jQuery Attribute Selectors
jQuery uses XPath expressions to select elements with given attributes.
$(“[href]”) select all elements with an href attribute.
$(“[href=’#’]”) select all elements with an href value equal to “#”.
$(“[href!=’#’]”) select all elements with an href attribute NOT equal to “#”.
$(“[href$=’.jpg’]”) select all elements with an href attribute that ends with “.jpg”.
jQuery CSS Selectors
jQuery CSS selectors can be used to change CSS properties for HTML elements.
নিচের উদাহরণটিতে p elements গুলির background কালার হলুদ রঙে পরিবর্তিত হয়ে যাছে।
উদাহরণঃ
<html>
<head>
<script type=”text/javascript” src=”jquery.js”></script>
<script type=”text/javascript”>
$(document).ready(function(){
$(“button”).click(function(){
$(“p”).css(“background-color”,”yellow”);
});
});
</script>
</head>
<body>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>Click me</button>
</body>
</html>