Skip to content
Advertisement

Tag: selectors-api

querySelector not detecting element until it’s inspected

My problem appears to be quite similar to this problem: Document.querySelector returns null until element is inspected using DevTools, however there are some significant differences that are quite confusing and suggest that the problem may be different. I’m trying to write code that replaces text in the input box on Google Chat, so I am using document.querySelector. The input field

querySelectorAll for element contain specific class

I have few divs that contain two classes such as this: where {{month.year + ‘-‘ + month.monthName + ‘-‘ + ‘end’}} for a certain month is 2018-August-end I want to select the divs that contain only 2018-August-end which I store into a variable so I tried something like this but I get this error Uncaught DOMException: Failed to execute ‘querySelectorAll’

Getting selected options with querySelectorAll

I wonder if it’s possible in Javascript to get the currently selected options in a <select multiple> field using the Selctors API rather than a “stupid” iteration over all options. select.querySelectorAll(‘option[selected=”selected”]’) only returns the options that were marked as preselected in the original HTML, which is not what I’m looking for. Any ideas? Answer document.querySelectorAll(‘option:checked’) Works even on IE9 😉

Advertisement