Javascript get element6/4/2023 ![]() ![]() This is pretty much Andrew's answer, using RegExp.test instead of String.indexOf, since it seems to perform better for multiple operations, according to jsPerf tests. ![]() Note The tag name '' returns all child elements. Syntax: selector document. The getElementsByTagName () method returns an HTMLCollection. Method 2: Using JavaScript to get the element by name and pass it on to jQuery The JavaScript getElementsByName () method can be used to select the required element and this can be passed to a jQuery function to use it further as a jQuery object. If the items are inserted in order, you could use: items 0. Note that you will need to amend the onclick to include the event in the arguments, though. I'm surprised there are no answers using Regular Expressions. The getElementsByTagName () method returns a collection of child elements with a given tag name. With the method you're using - where you expect the event to be passed as an argument to the function - you can use event.target to access the clicked element. ![]()
0 Comments
Leave a Reply. |