jquery-selectors

jQuery selector help - how to find element whose ID starts and ends with specific characters

风流意气都作罢 提交于 2019-12-19 06:05:49
问题 I have a page that's created dynamically. It can have a number of different radio buttons with ID's like so: <input type="radio" id="cc-radio-opt-0" /> <input type="radio" id="cc-radio-opt-1" /> <input type="radio" id="gc-radio-opt-0" /> <input type="radio" id="gc-radio-opt-1" /> In order to write change functions, I'm doing something like this: $('[id^=cc-radio-opt-]').live("change", function() { var idx = $(this).attr('id').split('-').pop(); }); This works well. But now, inside that change

How to select all elements with particular ARIA value using jQuery?

你离开我真会死。 提交于 2019-12-19 05:17:14
问题 Given i have a sample page that looks like this: <!DOCTYPE html> <html> <body> <h1 aria-controls="name1">heading</h1> <p aria-controls="name2">paragraph</p> <span aria-controls="name1">span</span> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> </body> </html> How would i use jQuery to select the (2) elements with their aria-controls attribute set to name1 ? (ignoring the fact that the element types are different). Thank you!

Why is “#.id” a bad selector in CSS/jQuery yet it works in an HTML anchor?

旧城冷巷雨未停 提交于 2019-12-19 05:03:39
问题 I'm using JSDoc. It generates ids with a period as in <a id=".someMethodName"></a> If another part of the page has <a href="#.someMethodName"></a> That works perfectly. Clicking the second anchor scrolls to the first. But, neither document.querySelector nor jQuery will find the anchor. Why does the browser itself accept this anchor but jQuery and querySelector do not? test("document.querySelector('#.someMethodName')", function() { document.querySelector('#.someMethodName'); }); test("$('#

jQuery - Remove all classes with similar names

半城伤御伤魂 提交于 2019-12-18 21:50:02
问题 Is there any better way to do this? $('element').removeClass('class-1').removeClass('class-2').removeClass('class-3').removeClass('class-5') ... to .removeClass('class-105') :) I want to remove all class-(n) classes. 回答1: Get the classes of the element, process it as a string, and put it back: $('element').attr( 'className', $('element').attr('className').replace(/\bclass-\d+\b/g, '') ); Edit: The attr method has since changed, and it no longer reads properties, so you have to use the

How to select an element which parent is not specified class?

谁都会走 提交于 2019-12-18 18:50:55
问题 I want to hide an element if its parent does not have a certain class: HTML <li class="current_page_parent"> <a href="parent.html">Parent</a> <ul class="children"> <li>foo</li> <li>bar</li> </ul> </li> jQuery jQuery("ul.children").hide(); Currently always hides <ul class="children"> regardless of class. I would like to close it only if parent is :not an <li class="current_page_parent"> . I've tried: jQuery("ul.children:not(:parent.current_page_ancestor)").hide(); with no luck. 回答1: Try this:

Getting first visible element with jQuery

我怕爱的太早我们不能终老 提交于 2019-12-18 18:47:23
问题 Trying to get the first visible element of a list using jQuery's :first and :visible pseudo-selectors, as suggested here: https://stackoverflow.com/a/830611/165673 but it's not working: Fiddle: http://jsfiddle.net/FAY9q/4/ HTML: <ul> <li>Item A</li> <li>Item B</li> <li>Item C</li> </ul> <ul> <li style="display:none;">Item A</li> <li>Item B</li> <li>Item C</li> </ul> JQUERY: $('li:visible:first').css('background','blue'); The first item in each list should turn blue... 回答1: Try using this: $(

Select element unless it has an ancestor of a given class using just a selector

一曲冷凌霜 提交于 2019-12-18 18:46:31
问题 Suppose I have the following HTML: <div class="foo"> <ul> <li>One</li> <li>Two</li> </ul> </div> <!-- not originally here --> <div class="bar"> <ul> <li>Three</li> <li>Four</li> </ul> </div> I want to select all li elements that are not descendants of an element with class foo . I know I can do it with a fancy filter function, but I'm wondering whether I can do it with just a selector. First I tried: $(":not(.foo) li") Unfortunately this doesn't work since the li has other ancestors without

JQuery multiply input values of table rows

拜拜、爱过 提交于 2019-12-18 18:26:50
问题 I want to calculate each row's total price by multiplying individual row's inputs and then finally calculate a grand total by adding all the total values of the Total column using JQuery. I am only getting the first row to display total when I enter values. Any help will be greatly appreciated. <script type="text/C#" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function () { $(".txtMult").each(function () {

jquery escape square brackets to select element

本小妞迷上赌 提交于 2019-12-18 17:06:33
问题 Consider a input element <input id="meta[152][value]" type="text" /> Here the input field is dynamically generated. I need to select that field. So I used, alert($('#meta[152][value]').val()); But this seems to be invalid. After searching I found, that the "square brackets" need to be escaped like #meta\\[152\\]\\[value\\] So how to do that ? I currently use this code, var id = "#meta[152][value]" // (I get this value by another method) I need the escaping to be done here. So that i can use

How do I combine logical OR with logical AND within a jQuery attribute selector?

自闭症网瘾萝莉.ら 提交于 2019-12-18 13:14:13
问题 Given the following XML: <users> <user state="CA" sex="m">Max</user> <user state="AZ" sex="f">Jen</user> <user state="OR" sex="f">Kim</user> <user state="NV" sex="m">Bob</user> <user state="CA" sex="m">Jon</user> <user state="AZ" sex="m">Jim</user> <user state="OR" sex="f">Joy</user> <user state="NV" sex="f">Amy</user> </users> Using jQuery, is there a way to select users who are male and are either from CA or NV, but without using the filter function? To be clear, I know that $(xml).find(