Reputation: 33
I was browsing for examples for my page and ran across a weird JQuery selector. Can any of you explain how does it work, and can I use it to select ID's in HTML which have unique indexing.
//The selector which I don't know how it works
//what is "^" exactly for?
"div[id^='myModal']"
//How Jquery for me dyanimcally creates HTML with Array elements and indexes ID's
id=\"Modals_" +index+ "\"
Upvotes: 0
Views: 35
Reputation: 409
a[href^="https"] this mean is Selects every element whose href attribute value begins with "https" you can find meaning of selector in this link https://www.w3schools.com/cssref/css_selectors.asp
about id=\"Modals_" +index+ "\"
index is variable and you can use this for ID like this code
ID="Modals_"+index
$("p").attr("id",ID)
Upvotes: 1
Reputation: 245
"div[id^='myModal']" it means that all the div's with starting of ID element with "myModal" for exmple myModal1, myModal2 etc/...............
Upvotes: 0