jquery-selectors

jQuery get all images within an element larger than a specific size

 ̄綄美尐妖づ 提交于 2020-01-12 20:55:33
问题 So I have an image placeholder and I want to load the first image from the HTML within a DIV element that is larger than 70px width or height. Then provide a next and previous link to load the next image that is larger than 70px. I know jQuery has a next & prev selector but I'm not sure how I would tie this in with next and previous links or specify an image size. 回答1: To get all images larger that some size you can use something like this: var allImages = $('img', yourDivElement) var

Find elements which have greater font-size than specified

假装没事ソ 提交于 2020-01-12 09:14:27
问题 I am trying to define a JQuery statement for finding elements which have a greater (or lesser respectively) font-size than an input value. Possible input values: "12px" "14pt" "120%" and so on... My first approach is more of a draft because it cannot work this way. But maybe you have ideas how to achieve a solution. Here is what i have so far (the input value comes from elsewhere and is variable): $('*').filter(function() { return $(this).css('font-size') > '12px'; }) Anyone? Update I was

Does CSS have anything like jQuery's :has()?

做~自己de王妃 提交于 2020-01-11 08:23:49
问题 In CSS (any version), is there something like, or any other way of doing anything like the :has() selector in jQuery? jQuery(':has(selector)') Description: Selects elements which contain at least one element that matches the specified selector. http://api.jquery.com/has-selector/ 回答1: No, there isn't. The way CSS is designed, does not permit selectors that match ancestors or preceding siblings; only descendants ( and > ), succeeding siblings ( ~ and + ) or specific children ( :*-child ). The

How to order dynamically created elements based on a custom attribute? [closed]

有些话、适合烂在心里 提交于 2020-01-11 07:53:08
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 8 years ago . This function seems to work fairly well for sorting divs based on ID: JS var div = $("<div id='3.5'>AA</div>"); div_id_after = Math.floor(parseFloat(div.get(0).id)); $('#'+div_id_after).after(div); HTML <div id=

Is .find() faster than basic descendant selecting method?

本秂侑毒 提交于 2020-01-11 05:01:05
问题 Slide 30 in Paul Irish's blog mentioned: $('#container').find('div.robotarm') is faster than $('#container div.robotarm') Is this true? 回答1: Maybe in an earlier version of jQuery that was the case. However, the expression $('#container div.robotarm') is normalized through jQuery into $('#container').find('div.robotarm') So the only reason why $('#container div.robotarm') should be slower is because of function call overhead. But, that would really be a trivial difference. If that call wasn't

Find elements with click event

梦想与她 提交于 2020-01-11 04:43:08
问题 How can each element with a click event found by jQuery (2.2.1)? This seems to not work anymore: console.log($._data( $(this)[0], 'events' )) 回答1: Try $.each($("*"), function(index, value) { if ($._data($(value)[0], "events") != undefined) { console.log($._data($(value)[0], "events") , window.jQuery().jquery); }; }); jsfiddle http://jsfiddle.net/guest271314/3dhMM/ jQuery: version: v2.1.2-pre e5190982c40d7ac8ab9bdb2e7e4334f0e123ef66 url: http://code.jquery.com/jquery-git2.js date: 2014-07

jQuery selector for links with # in href attribute

只愿长相守 提交于 2020-01-10 08:47:10
问题 I tried to use this jQuery selector: $("a:has(href*=#)").click(function() { alert('works'); }); but it doesn't seem to work. I would like to select all tags which have anchor in href attribute (has # symbol there) 回答1: $("a[href*=#]").click(function(e) { e.preventDefault(); alert('works'); }); 回答2: *= will filter attributes that contain the given string anywhere $("a[href*='#']").click(function() { alert('works'); }); Also note that $("a[href^='#']").click(function() { alert('works'); });

jQuery selector for links with # in href attribute

て烟熏妆下的殇ゞ 提交于 2020-01-10 08:47:01
问题 I tried to use this jQuery selector: $("a:has(href*=#)").click(function() { alert('works'); }); but it doesn't seem to work. I would like to select all tags which have anchor in href attribute (has # symbol there) 回答1: $("a[href*=#]").click(function(e) { e.preventDefault(); alert('works'); }); 回答2: *= will filter attributes that contain the given string anywhere $("a[href*='#']").click(function() { alert('works'); }); Also note that $("a[href^='#']").click(function() { alert('works'); });

jQuery selector optimization

情到浓时终转凉″ 提交于 2020-01-09 12:48:40
问题 Be specific on the right-hand side of your selector, and less specific on the left. // unoptimized $('div.data .gonzalez'); // optimized $('.data td.gonzalez'); Quote Source Could someone explain why the less specific left is faster as a CSS selector? Is this a Sizzle thing or does the same apply for document.querySelectorAll ? Are there any speed gains using "similarly optimised" CSS selectors in CSS files? 回答1: jQuery's Sizzle Engine parse selectors from right to left, so it's true. There

Should I cache $(this) in jQuery if it is used more than once?

那年仲夏 提交于 2020-01-09 11:13:34
问题 I know that you are supposed to cache the results of a selector if you use it more than once. An example would be: var $selected = $('.some-selected-element'); process($selected); doStuff($selected); But is there any performance benefit to caching $(this) if it is used multiple times? $('.some-selector').hover(function () { if (!$(this).hasClass('some-other-class')) { $(this).addClass('another-class'); } process($(this)); } 回答1: Yes, there's a performance increase, because it prevents jQuery