dom-traversal

Closest ancestor matching selector using native DOM?

人走茶凉 提交于 2019-11-27 21:22:19
Is anybody working on a jQuery.closest() equivalent in the DOM api? Looks like the Selectors Level 2 draft adds matches() equivalent to jQuery.is() , so native closest should be much easier to write. Has adding closest() to Selectors come up? Element.closest() its support Implementing such function with Element.matches() seems not optimal in terms of performance, cause apparently matches() will make a call to querySelectorAll() every time you test a parent, while only one call is sufficient for the job. Here's a polyfill for closest() on MDN. Note a single call to querySelectorAll() if (window

jQuery append and remove dynamic table row

本小妞迷上赌 提交于 2019-11-27 07:28:15
I can add many rows for a table, but I can't remove many rows. I only can remove 1 row per sequential add. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("#addCF").click(function(){ $("#customFields").append('<tr valign="top"><th scope="row"><label for="customFieldName">Custom Field</label></th><td><input type="text" class="code" id="customFieldName" name="customFieldName[]" value="" placeholder="Input Name" />   <input type="text" class="code" id="customFieldValue" name="customFieldValue[]" value="" placeholder=

jQuery: prev(<selector>) not working?

微笑、不失礼 提交于 2019-11-27 06:38:08
问题 I'm having trouble using prev() in jQuery where it's not selecting the right element. My HTML structure is as follows: <section id="about"> ... </section> <hr> <section id="contact"> ... </section> The "active" section is #contact. I want to select the previous section skipping over the <hr> active = active.prev('section') doesn't seem to be working. I think I may be reading the docs wrong... If I take out the <hr> everything works beautifully. Any ideas on how to skip the <hr> on prev()? TIA

Closest ancestor matching selector using native DOM?

你离开我真会死。 提交于 2019-11-27 04:30:59
问题 Is anybody working on a jQuery.closest() equivalent in the DOM api? Looks like the Selectors Level 2 draft adds matches() equivalent to jQuery.is(), so native closest should be much easier to write. Has adding closest() to Selectors come up? 回答1: Element.closest() its support Implementing such function with Element.matches() seems not optimal in terms of performance, cause apparently matches() will make a call to querySelectorAll() every time you test a parent, while only one call is

jQuery append and remove dynamic table row

你。 提交于 2019-11-26 13:08:00
问题 I can add many rows for a table, but I can\'t remove many rows. I only can remove 1 row per sequential add. <script src=\"//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js\"></script> <script> $(document).ready(function(){ $(\"#addCF\").click(function(){ $(\"#customFields\").append(\'<tr valign=\"top\"><th scope=\"row\"><label for=\"customFieldName\">Custom Field</label></th><td><input type=\"text\" class=\"code\" id=\"customFieldName\" name=\"customFieldName[]\" value=\"\"

getElementsByClassName() doesn&#39;t work in old Internet Explorers like IE6, IE7, IE8

独自空忆成欢 提交于 2019-11-26 00:26:04
问题 The following code: var borderTds = document.getElementsByClassName(\'leftborder\'); gives me an error message in Internet Explorer 6, 7 and 8: Object does not support this method How can I select elements by their class in these browsers? I prefer not to use JQuery. 回答1: This solution may help. This is a custom getElementsByClassName function implemented in pure javascript, that works in IE. Essentially what this script is doing is probing, one by one, all possible options and picks the best

What do querySelectorAll and getElementsBy* methods return?

被刻印的时光 ゝ 提交于 2019-11-25 21:29:42
问题 Do getElementsByClassName (and similar functions like getElementsByTagName and querySelectorAll ) work the same as getElementById or do they return an array of elements? The reason I ask is because I am trying to change the style of all elements using getElementsByClassName . See below. //doesn\'t work document.getElementsByClassName(\'myElement\').style.size = \'100px\'; //works document.getElementById(\'myIdElement\').style.size = \'100px\'; 回答1: Your getElementById() code works since IDs