Reputation: 1499
I have an element variable:
element = '<div class="c-element js-element">Something Here</div>';
Needed to select this element like:
$(element)
it returns no string return like:
n.fn.init [div.c-element.js-element, context: div.c-element.js-element] // and more
How can I select a given string element in javascript dom like jQuery selector?
Upvotes: 0
Views: 333
Reputation: 91
$(element).get(0)
will return the DOM element.
Also you could use native bindings:
const element = document.createElement('div');
element.classList.add('c-element', 'js-element');
element.innerHTML = 'Something here'
Upvotes: 1