স্টার্ট ওয়িথ এবং হ্যাজ সিলেক্টর(start with and has selector):জে-কোয়েরী -(পর্ব-১৬)

স্টার্ট ওয়িথ সিলেক্টর (start with selector) :
যেসকল উপাদানের attribute এর value searching value দ্বরা শুরু হয়েছে তাদেরকে select করবে। অর্থাৎ, এটি attribute এর value এর প্রথম অংশের দিকে নজর রাখে। এক্ষেত্রে প্রথম অংশের পরে space থাকা বাঞ্চনিয় নয়।

start with selector Syntax : $(‘[A^=”B”]’)

Description :

ঐ সকল element কে select কর যাদের A attribute এর value ‘B’ দ্বারা শুরু হয়েছে।

Example :

$(‘a[rel^=nof]’) – এটি যেসকল anchor (<a></a>) element এর rel attribute এর value ‘nof’ দ্বারা শুরু হয়েছে তাদের সকলকে select করবে।

উদাহরন Code :

[sourcecode language=”html”]
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<input name="newsletter" />

<input name="milkman" />
<input name="newsboy" />
<script>
$(‘input[name^="news"]’).val(‘news here!’);
</script>

</body>
</html>
[/sourcecode]

ফলাফল(output):

Selector Example

হ্যাজ সিলেক্টর(Has selector) : যেসকল উপাদানের এর searching attribute টি রয়েছে তাদেরকে select করবে। শুধু মাত্র এ selector টি ই attribute এর value এর উপর নির্ভিরশীল নয়, attribute এর উপর নির্ভিরশীল।

Has Selector Syntax : $(‘[A]’)

Description :

ঐ সকল element কে select কর যাদের A নামক attribute আছে।

Example :

$(‘a[rel]’) – এটি যে সকল anchor(<a></a>) element এর ‘rel’ attribute আছে তাদের সকলকে select করবে।

উদাহরন Code :

[sourcecode language=”html”]
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div>no id</div>
<div id="hey">with id</div>

<div id="there">has an id</div>
<div>nope</div>
<script>
$(‘div[id]’).one(‘click’, function(){
var idString = $(this).text() + ‘ = ‘ + $(this).attr(‘id’);
$(this).text(idString);
});
</script>

</body>
</html>
[/sourcecode]

Click me to show Demo

………………………………………………………………………………
আজ এখানেই শেষ করলাম। “HAVE A GOOD PROGRAMMING”

জে-কোয়েরী ধারাবাহিক টিউটোরিয়ালঃ

Leave a Comment