Posts

Showing posts with the label closest

javascript : .closest(cssSelector)

  javascript : .closest( cssSelector ) Target: Applicable with any DOM element. getElementById getElementsByTagName getElementsByClassName getElementsByName querySelector querySelectorAll select etc. Description : it search for closest parent element that matched with the selector. It traverse parentNode to parentNode untill matched with selector if no any parent element matched then it return empty array of nodeElementsList instead of null so nested statement not generate error due to null reference. Note : it start searching of selector from the element itself. That's mean if the element matches with the selector it return itself. Syntax: DOMElement.closest( cssSelector ) DOMNodeList.closest( cssSelector ) HTMLCollection.closest( cssSelector ) Usase: document.getElementById('firstDiv').closest( 'form' ) it search for firstDiv Element's parent form. document.getElementsByTagName('div').closest( 'form' ) the getElementsByTagName selects all div a...

javascript : .find(cssSelector)

  javascript : .find( cssSelector ) Target: Applicable with any DOM element or elements List. getElementById getElementsByTagName getElementsByClassName getElementsByName querySelector querySelectorAll select etc. Description : it search selector in the element/elements list children and return all children DOMNodeList that are matched with selector passed. Syntax: DOMElement.find( selector ) DOMNodeList.find( selector ) HTMLCollection.find( selector ) Usase: document.getElementById('firstDiv').find( 'input' ) it search input elements in firstDiv and return DOMNodeList of all input elements inside firstDiv. document.getElementsByTagName('div').find( 'input' ) the getElementsByTagName selects all div and find() method seaches input elements in all dives and return DOMNodeList of input elements. document.getElementsByClassName('FirstDiv').find( 'input' ) the getElementsByClassName selects all elements having class FirstDiv and find() method...

javascript : .visible()

  javascript : .visible() Target: Applicable with any DOM elements List. getElementById getElementsByTagName getElementsByClassName getElementsByName querySelector querySelectorAll select etc. Description : return DOMNodeList that are visible in selector. Syntax: DOMElement.visible() DOMNodeList.visible() HTMLCollection.visible() Usase: document.getElementById('firstDiv').visible() if the div having id firstDiv is visible then return DOMNodeList having firstDiv document.getElementsByTagName('div').visible() the getElementsByTagName selects all div and visible() method returns only all divs that are visible as DOMNodeList. document.getElementsByClassName('FirstDiv').visible() the getElementsByClassName selects all elements having class FirstDiv and visible() method returns elements that are visible in list as DOMNodeList. document.getElementsByName('FirstDiv').visible() the getElementsByName selects all elements having name attribute "FirstDiv" ...

javascript : .select(cssSelector)

  javascript : .select( cssSelector ) Target: Applicable with any DOM element or elements List. document getElementById getElementsByTagName getElementsByClassName getElementsByName querySelector querySelectorAll select find filter filterNot not visible nextAll prevAll next prev closest Description : It search selector element in the document/element/elements list itself or children and return all DOMNodeList that are matched with selector passed. Syntax: Document.select( selector ) DOMElement.select( selector ) DOMNodeList.select( selector ) HTMLCollection.select( selector ) Note : selector may be any css selector string or DomElement Usase: document.select('#firstDiv  input' ) it search input elements in firstDiv and return DOMNodeList of all input elements inside firstDiv. document.select(' .divExample ').select(' li ).select(' span ')  It find ".divExample" in document and then find "li" in result list and then find "span" i...

javascript : String.toKebabCase()

  javascript : String .toKebabCase() Target: Applicable with  String  Data Type. Description : convert string to a single word in kebab-case format. Every words separated by '-'. Note: convert into kebab-case from PascalCase, snake_case and camel-case. Syntax: String .toKebabCase() Usase: " hello     how     are     you ? ".toKebabCase() It return string "hello-how-are-you-?" "helloHowAreYou?".toKebabCase() It return string "hello-how-are-you-?" "hello_how_are_you_?".toKebabCase() It return string "hello-how-are-you-?" "HelloHowAreYou?".toKebabCase() It return string "hello-how-are-you-?" Download MYJS.js Include in you project landing page (master page) and it will extends your DOM and JavaScript Objects.