jquery-selectors

jQuery selecting a selector with namespaced element

一世执手 提交于 2019-12-17 16:17:21
问题 How would I select the following in jQuery? <ns:text value="my value" /> I have tried the snippets below, but to no avail. Is this possible? var x= $('ns:text').attr('value'); return x; var x= $('text').attr('value'); return x; 回答1: You're looking for: var x= $('ns\\:text').attr('value'); return x; Ref: http://docs.jquery.com/Selectors#Special_characters_in_selectors 回答2: Take a look at JQuery, XML and namespaces. It seems that this should work: var x = $("ns\\:text").attr("value"); 回答3: I

jQuery - multiple :not selector

谁都会走 提交于 2019-12-17 15:53:14
问题 I'm trying to target page-wide links that do not start with a '#' and do not include in-line javascript but I'm having problems figuring out how to structure the selector properly. Based on what I've googled about multiple selectors this should work, both selectors work independently, just not together! $('a:not([href*=javascript]), a:not([href^=#])') .each(function(){... 回答1: Try using $('a:not([href*=javascript]):not([href^=#])') ... 回答2: You could also try: $('a').not('[href^=#],[href*

Is there a wildcard selector for identifiers (id)?

南笙酒味 提交于 2019-12-17 15:24:03
问题 If I have an unknown amount of identifiers sharing a specific naming-scheme, is there a way to grab them all at once using jQuery? // These are the IDs I'd like to select #instance1 #instance2 #instance3 #instance4 // What do I need to add or how do I need to modify this jQuery selector in order to select all the IDs above? ("#instanceWILDCARD").click(function(){} 回答1: The attribute starts-with selector ('^=) will work for your IDs, like this: $("[id^=instance]").click(function() { //do stuff

jQuery: How to get to a particular child of a parent?

落花浮王杯 提交于 2019-12-17 15:22:34
问题 To give a simplified example, I've got the following block repeated on the page lots of times (it's dynamically generated): <div class="box"> <div class="something1"></div> <div class="something2"> <a class="mylink">My link</a> </div> </div> When clicked, I can get to the parent of the link with: $(".mylink").click(function() { $(this).parents(".box").fadeOut("fast"); }); However... I need to get to the <div class="something1"> of that particular parent. Basically, can someone tell me how to

Hide all but $(this) via :not in jQuery selector

一个人想着一个人 提交于 2019-12-17 15:22:09
问题 Advanced title, simple question: How can I do the following in jQuery (hiding everything except $(this) )? $("table tr").click(function() { $("table tr:not(" + $(this) + ")").hide(); // $(this) is only to illustrate my problem $("table tr").show(); }); 回答1: $(this).siblings().hide(); Traversing/Siblings 回答2: $("table.tr").not(this).hide(); As an aside, I think you mean $("table tr") (with a space instead of a dot). The way you have it, it selects every table which has a class of tr (eg,

Performance differences between using “:not” and “.not()” selectors?

橙三吉。 提交于 2019-12-17 13:45:23
问题 Are there any speed/efficiency differences between the following two lines. $("table td:not(:first-child)") and $("table td").not(":first-child") I would think that the first would be better since it is removes objects, but is there an actual difference and is it substantial. Thanks 回答1: As you can see from the jsperf test, :not is on average about twice as fast. Overall though this performance will likely be a very small part of your overall execution time. The jquery docs state: The .not()

How to use multiple jquery object variables as selectors?

馋奶兔 提交于 2019-12-17 10:58:34
问题 In jQuery, selecting more than one element can be done like this: $("#id1,#id2").show(); But when I have two jQuery objects, I don't seem to be able to select more than one using the variables themselves. For example: var jqId1 = $("#id1"); var jqId2 = $("#id2"); $(jqId1).show(); // This works. $(jqId1,jqId2).show(); // This only shows jqId1. See jsFiddle: http://jsfiddle.net/jr9Q2/ Is there another way of specifying multiple jq variables as selectors? 回答1: You can use add : jqId1.add(jqId2)

CSS selector to select an id with a slash in the id name?

坚强是说给别人听的谎言 提交于 2019-12-17 10:52:14
问题 I've got <span id="/about-us"> being generated by this CMS I'm using. I'd like to select this element with jQuery but it doesn't seem to like selecting elements with a slash in them. Is this possible? 回答1: you can do $("#\\/about-us") 回答2: you can do it like this $("span[id*='/about-us']") where it will return the span with '/about-us' in it's id attribute. 回答3: Use the regular way: document.getElementById('id/with/slashes') 回答4: see Regex Selector for jQuery or related question 回答5: You can

jQuery: how to find first visible input/select/textarea excluding buttons?

坚强是说给别人听的谎言 提交于 2019-12-17 10:44:39
问题 I tried $(":input:not(input[type=button],input[type=submit],button):visible:first") but it doesn't find anything. What is my mistake? UPD: I execute this on $(document).load() <script type="text/javascript"> $(window).load(function () { var aspForm = $("form#aspnetForm"); var firstInput = $(":input:not(input[type=button],input[type=submit],button):visible:first", aspForm); firstInput.focus(); }); </script> and in the debug I can see that firstInput is empty. UPD2: I'm in ASP.NET page running

Find all elements based on ids using regex on jQuery selector

妖精的绣舞 提交于 2019-12-17 09:32:01
问题 I've got several elements with unique ids like so: <div id='item-1-top'></div> <div id='item-2-top'></div> <div id='item-3-top'></div> I was hoping that the following would work using jQuery: $("#item-[.]+-top").each(function() { $(this).hide(); }); I do not have a good grasp of regular expressions and I would appreciate some input, as the above appears to be incorrect. 回答1: If you were doing this with regex, the expression would simply be: item-\d-top Where the \d indicates any single digit