I am using nodejs and have a variable with stored html code. To manipulate the content, I would like to get all defined ids. I tried to use jquery, but I am not quite familiar with the framework. I tried something like this:
const { JSDOM } = require( "jsdom" );
const { window } = new JSDOM( "" );
const $ = require( "jquery" )( window );
let Ids = [];
$(myHtmlCode).find('*').each(function(){ IDs.push(this.id); });
The output looks like: [ 'id1', '', '', 'id2', '', '', '', 'id3', '', 'id4', '', '' ]
Is there a better way to do that?
Would be happy for some help. Thanks!
IdsandIDs. JavaScript identifiers are case-sensitive, they need to match. I assume this is just an error retyping the code for the question (copy and paste is generally best).