एचटीएमएल डोम मैच () विधि
तत्व वस्तुउदाहरण
निर्धारित करें कि कोई तत्व CSS चयनकर्ता से मेल खाता है या नहीं:
var element = document.getElementById("myElement");
if (element.matches(".container")) {
element.innerHTML = "This element matches the \".container\" CSS selector";
} else {
element.innerHTML = "This element does not match the \".container\" CSS selector";
}
परिभाषा और उपयोग
यह matches()
विधि एक बूलियन मान लौटाती है जो दर्शाती है कि कोई तत्व किसी विशिष्ट CSS चयनकर्ता से मेल खाता है या नहीं।
युक्ति: सभी CSS चयनकर्ताओं की सूची के लिए, हमारे CSS चयनकर्ता संदर्भ देखें ।
ब्राउज़र समर्थन
तालिका में संख्याएं पहले ब्राउज़र संस्करण को निर्दिष्ट करती हैं जो पूरी तरह से विधि का समर्थन करता है।
Method | |||||
---|---|---|---|---|---|
matches() | 33.0 | 18.0 | 34.0 | 7.0 | 21.0 |
वाक्य - विन्यास
element.matches(selectors)
पैरामीटर मान
Parameter | Description |
---|---|
selectors |
Required. Specifies one or more CSS selectors to match the element. These are used to select HTML elements based on their id, classes, types, attributes, values of attributes, etc. For multiple selectors, separate each selector with a comma. The returned element depends on which element that is first found in the document (See "More Examples"). Tip: For a list of all CSS Selectors, look at our CSS Selectors Reference. |
टेक्निकल डिटेल
प्रतिलाभ की मात्रा: |
एक बूलियन, यह दर्शाता है कि सीएसएस चयनकर्ता द्वारा तत्व का मिलान किया जा सकता है या नहीं:
|
---|
और ज्यादा उदाहरण
उदाहरण
पता लगाएँ कि क्या कोई तत्व एकाधिक चयनकर्ताओं में से किसी एक से मेल खाता है:
var element = document.getElementById("myElement");
if (element.matches(".container, .wrapper")) {
element.innerHTML = "This element matches either the \".container\" CSS selector or the \".wrapper\" selector.";
} else {
element.innerHTML = "This element does not match any of the selectors.";
}
संबंधित पृष्ठ
जावास्क्रिप्ट संदर्भ: तत्व। निकटतम () विधि।
तत्व वस्तु