dom-traversal

jquery selector needed to select all certain children of parent

久未见 提交于 2019-12-13 18:45:04
问题 I have a page with some tables on it. In each table the first row is normal but the rest of the rows have a class of hidden so that they are not displayed on load. In one of the cells on the first row of the table there is a link to click to view more details (fade in the hidden rows of that table). I'm struggling to get this to work though. So basically I need a selector that will find all the hidden rows that are in the same table as the element that's clicked so that they can be faded in.

How can I view the DOM while I am stepping through JavaScript breakpoints in Chrome?

牧云@^-^@ 提交于 2019-12-12 10:33:36
问题 In Chrome DevTools, while debugging JavaScript in the Sources tab(adding the "debugger;" line in JS code and then stepping through the code using F10/F11), how can I view the DOM while stepping through the code? If my JS is manipulating the DOM, it is very common that I need to step through the JS debugger and watch how the DOM elements are modified by my JS. For example, I might have to see how elements are being moved, whether they are being removed when they are supposed to, whether they

How to find <script> elements with particular value of “type” attribute?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 08:28:03
问题 Assuming the following script tag in a random HTML document: <script id="target" type="store"> //random JavaScript code function foo(){ alert("foo"); } foo(); </script> can anybody explain why the following expression doesn't find all elements of script with value store for their type attribute. var sel = $('#target script[type="store"]'); jQuery version: v1.7.2 Chrome version: 25.0.1364.172 (running on Debian Squeeze) 回答1: Your selector $('#target script[type="store"]') would match any

Transforming and appending a Dom Node

允我心安 提交于 2019-12-12 02:48:26
问题 I am using a function which takes in two DOM Elements - parent and child from different documents. I import the child element, transform it, then append it to the parent element. But, the last line in the following code is throwing a dom exception: org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it. Please see my code below: public void attachNodeToParent (Element parent, Element child) throws Exception { Document parent_doc =

Walk up DOM through multiple iframes in vanilla JS

匆匆过客 提交于 2019-12-11 13:26:19
问题 I'd like to be able to walk up the DOM from inside one or more nested iframes to grab and empty the parent div of the top iframe. I'd like my JS to work if there's just one iframe, or if there are two. I have a main page with this iframe: <div class="ad-unit"> <div class="ad-unit-large"> <iframe width="970" height="250" src="ad.html"></iframe> </div> </div> and then in ad.html , the page inside the iframe, I have this JavaScript: function getAdSlot() { var el = window.frameElement.parentNode;

jQuery: select tr's where td's meeting multiple criterias

十年热恋 提交于 2019-12-11 03:35:39
问题 I was wondering, whether it's possible to select <tr> 's from a <table> where <td> 's meets multiple conditions. For example (see sample table at the end ): Get all <tr> 's where first column is "Audi" AND second column is "red" I've allready find out how to filter by one collumn: $('tr:has(td:nth-child(1):contains("Audi"))').doSomeThing(); But my problem is how to filter with an AND condition like: $('tr:has(td:nth-child(1):contains("Audi") && td:nth-child(2):contains("red"))').doSomeThing()

Iterate over dom elements using document.getElementsByTagName, pass element as jquery object

橙三吉。 提交于 2019-12-10 17:56:43
问题 What I need is to iterate over the dom at some start element and then go through all elements below the start element. Here is what I was doing so far. function iterDomFromStartElem = function(startElem, callBackFunc) { if (startElem !== null) { var items = startElem.getElementsByTagName("*"); for (var i = 0; i < items.length; i++) { callBackFunc(items[i]); } } } The reason why I need to iterate over the dom from some start element is because our team recently got a request to implement font

difference between using MULTIPLE 'id' and 'class' attributes in HTML and CSS

烂漫一生 提交于 2019-12-10 11:19:05
问题 According to CSS principles when we want to implement reusability of styles we should use class attribute and when we know that there is an unique element in whole DOM structure we should use id attribute to that Element and then specify a style. But in this era of Web Applications, DOM structure can be too complex and there is a possibility of duplicate id . Best example would be #title . Its kind of name which can appear anywhere in the document. Now the best part is if I use #title or

appendChild Not Working

我与影子孤独终老i 提交于 2019-12-09 00:27:10
问题 HTML: <ul id="datalist"> </ul> JavaScript: function add(content){ ul=document.getElementsByTagName("ul"); var li=document.createElement("li"); li.innerHTML=content; ul.appendChild(li); } When I call add , Uncaught TypeError: Object #<NodeList> has no method 'appendChild' is thrown. Any idea why? 回答1: getElementsByTagName() does not return one element, it returns a NodeList, which is an array-like object. It basically means you can use it as an array. So you could do for example: var ul =

Dynamically Add and Remove Table Rows

痴心易碎 提交于 2019-12-08 09:36:48
问题 I am both adding and removing table rows with jQuery. I can add rows easily, but am having trouble removing ones that were created. You can view the page in action here: http://freshbaby.com/v20/wic/request_quote.cfm, with the relevant code pasted below. HTML <table style="width:600px;" id="product-list" summary="Lists details about products users wish to purchase"> <thead valign="top" align="left"> <tr> <th>Products</th> <th>Language</th> <th>Quantity</th> <th></th> </tr> </thead> <tbody