Skip to content Skip to sidebar Skip to footer

Javascript Getelementsbyclassname From Javascript Variable

I'm getting some html from a angular get request and I'm trying to get some specific elements from this response. Which is a list of div's with the class 'post-holder'. Extracting

Solution 1:

See the documentation for parseHTML:

Returns: Array

Description: Parses a string into an array of DOM nodes.

getElementsByClassName is a method on DOM elements, not on arrays. You need to loop over the array, check if each value is an element (as opposed to, for instance, a text node or a comment) and then call getElementsByClassName on the values.

Or you could just construct a jQuery object and use .find() on it instead.

Post a Comment for "Javascript Getelementsbyclassname From Javascript Variable"