dom

Chrome Extension: How do I get a web page to access functions defined by my content script?

夙愿已清 提交于 2021-01-28 21:39:00
问题 I'm programming a Chrome Extension, and I'm having it inject a content script which iterates through a few elements and attaches an onclick property to them which sends a message to my background script to execute a custom function on the DOM (the function defined in content scripts). To send a message from the web page to the extension, I must specify the extension ID which, as of now, I was manually getting from the extensions menu. Could I manage to query something for the extension's own

How to detect html div width and height once div is done resizing

╄→尐↘猪︶ㄣ 提交于 2021-01-28 20:15:27
问题 I am working with two divs where, one in the left is a collapsible container and the one in the right is a main container, something like this: ================================ | | | | | | | | | | div 1 | div 2 | | | | | | | ================================ I am collapsing div 1 using simple css class and when div 1 is not visible, div 2 expands in size and takes over rest of the space. Now I need to get the size of the div 2 once it is done with the resizing (which is not instant and it is

how to find the child node element of a div “contenteditable” where the cursor is writing on input event handler

江枫思渺然 提交于 2021-01-28 14:28:00
问题 I am trying to create a custom textarea editor by adding contenteditable as attribute on a div element that the text will be as text element and hashtag will be as span element, but the problem is when i want to add a hashtag between text and hashtag, to do that must to find the current index of child element that the cursor is writing, and then i can use inderBefore method to add this element after this index thanks my html code: <div class="text"> <div #textarea class="textarea"

Why is JavaScript invalidating DOM references after I manipulate the body's innerHTML?

回眸只為那壹抹淺笑 提交于 2021-01-28 12:16:00
问题 I was messing around with some simple JS code and came across the following: document.body.innerHTML += '<div id="div1">some text</div>'; var my_div = document.getElementById('div1'); document.body.innerHTML += '<div id="div2">some text</div>'; my_div.innerHTML = "some other text"; //doesn't work It would seem that after manipulating the parent element (the body) the reference to the DOM node is invalidated. What am I doing wrong here? 回答1: When you do this: document.body.innerHTML += '<div

Get current HTML of rendered page using Selenium

对着背影说爱祢 提交于 2021-01-28 09:21:53
问题 I'm strugling to get the rendered html code in selenium of a facebook app. After login I go to the app page and use time.sleep(20) to wait for it to fully render. I have already tried 3 solutions none of witch works: self.driver.page_source # This one returns source code self.driver.find_element_by_xpath('//*').get_attribute('outerHTML') self.driver.execute_script("return document.getElementsByTagName('html')[0].outerHTML") I'm using the google chrome driver and python3. Just to be clear.

Uncaught TypeError: Cannot read property 'quest' of undefined

烂漫一生 提交于 2021-01-28 09:20:04
问题 I know that this question may have been asked before but I believe that this awesome community can forgive me for this :) I am developing (Quiz time) app but there's a bug that's is killing me :( When I run this application every and press the lock button it acts as wanted but after a random number of clicks (may be 4 or 2) It stops and gives me this error : Uncaught TypeError: Cannot read property 'quest' of undefined at QuestionReset Here's the code $(document).ready(function () { var

fire the div mousemove while on document

不想你离开。 提交于 2021-01-28 07:10:16
问题 Im having a slider that increases width when click-hold and moved. But as soon as im getting my mouse outside of the slider it doesn't runs anymore. How can i make it also run when im moving my mouse outside the slider-container ? var classname = document.getElementsByClassName("slider-container"); const offset = function(el){ var rect = el.getBoundingClientRect(), scrollLeft = window.pageXOffset || document.documentElement.scrollLeft, scrollTop = window.pageYOffset || document

How do I append more than one child element to a parent element Javascript

匆匆过客 提交于 2021-01-28 07:00:32
问题 Good day everyone, I am new to programming, so I am sorry if my question looks stupid or too simple. I am trying to append 4 different child elements on a parent element. I am building a To Do List app, and I want the app to work in such a way that when the 'task' is entered and saved, the entered task will appear on a list with a checkbox, a delete button, and an edit button. I tried appending the child elements on their parent element using .appendchild() but it's not working. <Ol id="ol">

Javascript - Track any xmlhttprequest

╄→гoц情女王★ 提交于 2021-01-28 05:05:41
问题 Can I check any XmlHttpRequest, executable on page without adding addEventListener each of it? I try add document.addEventListener("loadend"...) but nothing happend. Looks like requests don't have a global events? // EDITED // I need detect new elements, which loaded by ajax. Great solution for it- here Using MutationObserver 回答1: I think you should rethink your design. Why do you want to do this. Are there better options? However if you really want to do this you could "hack" it by

Java XML dom: prevent collapsing empty element

心不动则不痛 提交于 2021-01-28 02:56:39
问题 I use the javax.xml.parsers.DocumentBuilder , and want to write a org.w3c.dom.Document to a file. If there is an empty element, the default output is a collapsed: <element/> Can I change this behavior so that is doesn't collapse the element? I.e.: <element></element> Thanks for your help. 回答1: This actualy depends on the way how you're writing a document to a file and has nothing to do with DOM itself. The following example uses popular Transformer-based approach: DocumentBuilderFactory