453 questions
1 vote
0 answers
110 views
Get closest descendant children with a specific class efficiently in vanilla Javascript
[EDIT] I'm sorry for my previous post, which was not very clear. I hope the updated question is less ambiguous! I created the following js method, which allows retrieving, in a descending manner, all ...
1 vote
1 answer
46 views
querySelector to querySelectorAll
Hi I want to make this code work for each element in the page but it only works for the first one. I can't make querySelectorAll() work. Only the first button works and the others don't. Thanks to all....
0 votes
0 answers
40 views
Targeting child nodes of a query selector all loop [duplicate]
I have a series of repeating HTML blocks on a page (over 200 times) that need to have some content tweaks made via some simple javascript. What I've done is use querySelectorAll to target all of the ...
0 votes
1 answer
233 views
How to use sibling combinator together with `:scope` in `querySelector`
Let's say I have an element and I want to select the next matching sibling. Normally, in css I'd be able to write <some selector for this element> ~ <selector for sibling>, but the sibling ...
1 vote
4 answers
133 views
Use wildcards to trace an a.href in the querySelectorAll NodeList
Let's say that instead of looking at the ID, I want to select all a.href elements that contain (a piece of) this example: if document.url is "www.youtube.com". var youtubeID = document....
1 vote
3 answers
105 views
looking for a smarter way to go though querySelectorAll nodelist (in GTM)
Tried a lot of solutions (like these https://dev.to/dailydevtips1/javascript-loop-queryselectorall-results-j6) but can't get the loop to work in GTM/Google Tag Manager. My working script - not very ...
0 votes
1 answer
34 views
javascript - querySelectorAll with addEventListener - how to get number of interacted element and variable from variable
I have HTML: <form name="form" .. <input type="text" name="title1" id="title1" class="f_title" value="smth LV"> <input type=&...
-2 votes
5 answers
101 views
How to perform this dynamic Find and replace in Javascript over user generated data?
I have an app that allows user to generate text with HTML code in the following format: <h2>User generated Dynamic Data 1</h2> <h3>User generated text 1.1</h3> <h3&...
-1 votes
2 answers
188 views
How to efficiently / correctly handle the click-event at any list-item of a multiple nested list-based menu / navigation?
Sorry if my question is really for newbie level... I have a 3 level list to build a menu, but I don't want to use href. I would like to use a specific attribute instead and call a javascript function ...
0 votes
0 answers
484 views
MutationObserver in Tampermonkey script always misses the first node
I have the following Tampermonkey custom script: // ==UserScript== // @name Hacker News // @namespace https://news.ycombinator.com/* // @version 2024-02-02 // @description try to take ...
2 votes
1 answer
175 views
Use previously cached selectors with querySelector()
How can I use previously cached selectors with certain aspects of querySelector() ? For example, I have this HTML / JavaScript: let L1, L2, L3; L1 = document.querySelector('#L1'); L2 = L1....
0 votes
2 answers
83 views
Stop next event listener from firing when one type of event is handled
I have 2 click listeners set up, these handle showing a modal and removing a note. These listeners use event delegation and is set up on parent container. The Note is rendered afters when users inputs ...
1 vote
4 answers
185 views
How to create unobstrusive JavasScript when there are hundreds of entries
I read about unobstrusive JavaScript and how Javascript should be not explicitly placed inside HTML code. Fine! But I have these hundreds of search results where I placed click events in the HTML ...
0 votes
1 answer
112 views
How to debug "not a valid selector" without access to the offending browser page
I made a TamperScript at work (in Chrome) that gathers a list of elements from a webpage. The script is used by many people without errors. But on one person's workstation it fails with the error: ...
-1 votes
1 answer
162 views
querySelectorAll is not returning updated nodelist inside a recursive function
I am trying to grab an element in the DOM that is created in the future. To simplify, When the user uploads an image by clicking on an upload button, a div is created in the DOM, which has a class ...