jquery-selectors

jQuery to get next match in the DOM after a particular element

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-22 06:33:03
问题 I hate to admit it but I'm stuck trying to figure out how to do this. e.g. pretending you have the following structure: <div> ... <div> <ul> <li> <a href="..."><img class="foo"/></a><!-- "previous" --> </li> <li> <a href="..."><img class="bar"/></a> </li> <li> <a href="..."><img class="foo"/></a><!-- I'm at this node --> </li> <li> <a href="..."><img class="baz"/></a> </li> <li> <a href="..."><img class="foo"/></a><!-- "next" 1 --> </li> </ul> </div> ... <div> <ul> <li> <a href="..."><img

Traverse up until some element

筅森魡賤 提交于 2019-12-22 05:01:32
问题 I have some element selected with jQuery selector. It is en element from list of elements with the same class ('my-elements'). Now I'd like to select element containing the selected one which is several levels above. How can I do this ? <div class="vote> (... several levels) <div class="my_element"></div> </div> the selector: var elements = $('.my_element'); var element = elements[0]; 回答1: The .closest() method should work (http://api.jquery.com/closest/): elements.closest("div.vote"); 回答2:

using variables in rel attribute in jquery selector

有些话、适合烂在心里 提交于 2019-12-22 04:22:31
问题 I'm using the rel attribute to match a div to a button. I use the button's id in the corresponding div's rel field. There are multiple buttons. When a button is clicked I want to show the corresponding div with the show() method, and to hide the other divs. The buttons work fine, but the divs are not responding. My gut says I'm not formatting the selector properly. Thanks. $("div.media_button").click(function (){ var relid = this.id; $("div.media_button").not(this).fadeTo("normal",0.33); $

using variables in rel attribute in jquery selector

跟風遠走 提交于 2019-12-22 04:22:14
问题 I'm using the rel attribute to match a div to a button. I use the button's id in the corresponding div's rel field. There are multiple buttons. When a button is clicked I want to show the corresponding div with the show() method, and to hide the other divs. The buttons work fine, but the divs are not responding. My gut says I'm not formatting the selector properly. Thanks. $("div.media_button").click(function (){ var relid = this.id; $("div.media_button").not(this).fadeTo("normal",0.33); $

How do I find all elements that have a title attribute using jQuery?

血红的双手。 提交于 2019-12-22 03:58:38
问题 How can I find all elements that have a title attribute using jQuery? It's for enabling tooltips using the tipsy jQuery plugin. 回答1: $('[title]') This will do the job. 回答2: You can use the Has Attribute selector: $("[title]").something(); 来源: https://stackoverflow.com/questions/4186849/how-do-i-find-all-elements-that-have-a-title-attribute-using-jquery

How to change Twitter Bootstrap tab, when button is pressed?

狂风中的少年 提交于 2019-12-22 03:52:15
问题 I need to change the tab when button is pressed, and the tab should be identified by id. The following code doesn't work for me - just the page is reloaded: <div class="form-actions"> <button class="btn btn-primary" id="btn-next">Next</button> <button type="reset" class="btn">Clear</button> </div> ... <div class="tab-pane active" id="2"> ... $("#btn-next").click(function(event) { $('#2').tab('show'); }); 回答1: You can use something like this: function nextTab(elem) { $(elem + ' li.active')

Does jQuery always return array?

懵懂的女人 提交于 2019-12-22 03:24:49
问题 Does jQuery always return array when selecting element (of course if at least one element exists)? Example: $('#Myelement') $('div') $('tbody') What if the selector is an ID? What if the selector is an element but has only one occurrence? 回答1: The jQuery function always returns a jQuery object (that is based on an array), even if there are no elements that matches the selector. That way you can always call a method that is supposed to affect the elements found, even if there are no elements

What does the dollar sign mean inside an attribute selector in jQuery?

你说的曾经没有我的故事 提交于 2019-12-22 03:20:54
问题 There is this jQuery which seems to look for all elements with id="scuba" , but then it uses attr() to pull the id out? Could "scuba" be part of the id and attr pulls the entire id out? I've never seen the $ inside an attribute selector, just outside like the example below. $('*[id$=scuba]').attr('id') So my questions are: What does the $ or $= do in this example What does this code do? 回答1: The dollar sign The first $ is a shorthand for the jQuery() function, the jQuery object constructor.

jQuery - Find Label By The Inner Text

拥有回忆 提交于 2019-12-22 01:32:50
问题 I was wondering if it was possible to find a label (or any element, really) by it's inner text. For example: <label for="myCheckbox">SuperSweetCheckbox</label> And I want to find it by the text SuperSweetCheckbox . I know this seems kind of counter-intuitive, but due to the nature of the app I'm working on it seems to be necessary. I realize that I can iterate through each of the labels but I'd prefer to avoid that option if at all possible. If anyone could provide some assistance, I'd

JQuery select all rows containing certain text within a td in the row

偶尔善良 提交于 2019-12-22 01:26:06
问题 I have a table for which I am attempting to select all rows which have a td containing the text 'Test' and then hide the td with class 'ms-vb-icon' on all the matched rows I intitally had the code below but this only hide the class on the last matched row $("td:contains('test'):last").parent().children(".ms-vb-icon").css("visibility","hidden"); So I tried this but its not working... $("tr:has(td:contains('test')").each(function(){ (this).children(".ms-vb-icon").css("visibility","hidden"); });