selectors-api

Is it possible to make querySelectorAll live like getElementsByTagName?

五迷三道 提交于 2020-01-01 04:26:25
问题 getElementsByTagName() has 2 great features: it is fast and it is live. But what if I want to get p strong . Of course I could refine a selection using getElementsByTagName() again but wouldn't I lose the live effect for the new p tags? Is there a way to turn querySelectorAll into a live selector? Or... is there a way to use getElementsByTagName() and getElementsByClassName() to create a function that works in a similar way (at least with descendants) as querySelectorAll but being live? 回答1:

Is it possible to make querySelectorAll live like getElementsByTagName?

会有一股神秘感。 提交于 2020-01-01 04:25:08
问题 getElementsByTagName() has 2 great features: it is fast and it is live. But what if I want to get p strong . Of course I could refine a selection using getElementsByTagName() again but wouldn't I lose the live effect for the new p tags? Is there a way to turn querySelectorAll into a live selector? Or... is there a way to use getElementsByTagName() and getElementsByClassName() to create a function that works in a similar way (at least with descendants) as querySelectorAll but being live? 回答1:

document.querySelectorAll get innerText of ALL selected elements at once pure javascript

℡╲_俬逩灬. 提交于 2020-01-01 03:32:12
问题 I want to get all innerText of a whole column of a very long html table (random length). I'm using this code: var tbEls = document.querySelectorAll('#tBodyID tr td:nth-child(cidx)'); Where cidx = the column index I want to extract content from. But such code extracts all the td elements (with the innerText inside them of course). But it doesn't extract directly all the innerText inside them. Cause of this I have to reprocess the returned tdEls array with a for loop to extract from each tbEls

for of loop querySelectorAll

↘锁芯ラ 提交于 2019-12-28 20:41:41
问题 Mozilla states that "for of loops will loop over NodeList objects correctly". (source: https://developer.mozilla.org/en-US/docs/Web/API/NodeList) However, this doesn't work in Chrome 43. Is this incorrect documentation or a browser bug? The copied example code used on a page with checkboxes: var list = document.querySelectorAll( 'input[type=checkbox]' ); for (var item of list) { item.checked = true; } 回答1: Edit: This is shipping in Chrome 51. Jake Archibald posted a simple fix: NodeList

Dynamically access function object property

不问归期 提交于 2019-12-26 05:38:13
问题 I need to check if the value of multiple textareas is equal to the property name of this object : function make_test(name, job, ID) { test = {}; test.name = name; test.job = job; test.ID = ID; return test; } new make_test("Paul", "manager", 1); //doesn't work new make_test("John", "employee", 2); //doesn't work new make_test("Jan", "employee", 2); //works It should only be a match if the value is equal to the name and if the index of the textarea is equal to the person's ID . For instance if

javascript - how to implement `not` in querySelector?

放肆的年华 提交于 2019-12-25 18:42:15
问题 Quick question: let's say you have 2 different types of <button> , First one looks something like this: <button class="test"> Second looks like this: <button class="test" disabled="disabled"> . Now, how can one achieve a selection of the disabled button without selecting the activated button? Cause if you go by class, querySelector would get both of them. Is there a way to implement some kind of logic into the selection made by querySelector ? Something like this maybe -> "select button with

Multiple “close” buttons on modal

回眸只為那壹抹淺笑 提交于 2019-12-25 02:33:04
问题 I am using the modals found here on Codrops. These modals have one close button (also closes when you click outside the modal), but I want to add more. The JavaScript is below: var ModalEffects = (function() { function init() { var overlay = document.querySelector( '.md-overlay' ); [].slice.call( document.querySelectorAll( '.md-trigger' ) ).forEach( function( el, i ) { var modal = document.querySelector( '#' + el.getAttribute( 'data-modal' ) ), close = modal.querySelector( '.md-close' );

Get and Download pictures with AngleSharp

被刻印的时光 ゝ 提交于 2019-12-24 12:34:52
问题 I started using Anglesharp for a Project, I need to get and download not only HTML but also images of the document. I know that in the Document object there is a property called Images, but appearently it doesn't get all of them, I did a test on a YouTube page and got only one (repeated several times). For example I'd like to get the thumbinail of the current video, and this seems to be inside a <meta> tag. To be more precise, images are stored inside this kind of tags: <meta content="https:/

Native Javascript querySelectorAll() with multiple/many pseudo selectors/matches

為{幸葍}努か 提交于 2019-12-24 06:42:21
问题 How can I place many pseudo selectors inside the native Javascript querySelectorAll()? Example: I want to search for an element with an id that starts with [id^=starting] and ends with [id$=ending]. (Couldn't find existing question so making my own and answering it) 回答1: With Native Javascript this would be the code: document.querySelectorAll('[id^=starting][id$=ending]'); or document.querySelectorAll('[id^='+startingString+'][id$='+endingString+']'); This will get an element which starts

querySelectorAll detecting value in input

六眼飞鱼酱① 提交于 2019-12-24 06:35:43
问题 I have multiple inputs I want to discriminate according to whether the user enters a value in it or not. <input type="text" class="foo"> <br/> <input type="text" class="foo" value = "D"> <br/> //and so on.. <button onclick="calculate()">Hightlight</button> The code I wrote only works with attribute values, instead of detecting "manually" typed values before launching the function : function calculate() { var allinputs = document.querySelectorAll('input[value][type="text"]:not([value=""])');