jQuery [attribute|=value] Selector
The jQuery [attribute|=value] selector is used to select each element with a specific attribute, with a specific string value (like “Beginner”) or starting string followed by a hyphen (like “Beginner-forBeginner”).
Syntax:
$("[attribute|='value']")
Parameter:
- attribute : This parameter is required to specify the attribute to be searched.
- value : This parameter is required to specify the string the attribute value should start with.
Example 1:
HTML
<!DOCTYPE html> < html > < head > < script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js" > </ script > < script > $(document).ready(function () { $("p[title|='w3wiki']").css( "background-color", "green"); }); </ script > </ head > < body > < center > < h1 >Beginner For Beginner</ h1 > < p title = "w3wiki" > Beginner1 </ p > < p title = "google" > Beginner2 </ p > < p title = "Tom" > Beginner3 </ p > < p title = "See You w3wiki" > Beginner4 </ p > < p title = "w3wiki-is the best place to learn" > Beginner5 </ p > </ center > </ body > </ html > |
Output:
Example 2:
HTML
<!DOCTYPE html> < html > < head > < script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js" > </ script > < script > $(document).ready(function () { $("button").click(function () { $("p[title|='google']").css( "background-color", "green"); }); }); </ script > </ head > < body > < center > < h1 >Beginner For Beginner</ h1 > < p title = "w3wiki" > Beginner1 </ p > < p title = "google" > Beginner2 </ p > < p title = "google- tom" > Beginner3 </ p > < p title = "See You w3wiki" > Beginner4 </ p > < p title = "w3wiki-is the best place to learn" > Beginner5 </ p > < button >Change color</ button > </ center > </ body > </ html > |
Output:
Contact Us