jquery-selectors

Selecting elements with a certain background color

ε祈祈猫儿з 提交于 2019-12-17 03:17:47
问题 I want to select a bunch of span s in a div whose CSS contains a particular background color. How do I achieve this? 回答1: if i understand the question correctly, the selector [attribute=value] will not work because <span> does not contain an attribute "background-color". you can test that out quickly to confirm it won't match anything: $('#someDiv span[background-color]').size(); // returns 0 given: .one, .two { background-color: black; } .three { background-color: red; } here's a snippet

Selecting elements with a certain background color

蓝咒 提交于 2019-12-17 03:17:11
问题 I want to select a bunch of span s in a div whose CSS contains a particular background color. How do I achieve this? 回答1: if i understand the question correctly, the selector [attribute=value] will not work because <span> does not contain an attribute "background-color". you can test that out quickly to confirm it won't match anything: $('#someDiv span[background-color]').size(); // returns 0 given: .one, .two { background-color: black; } .three { background-color: red; } here's a snippet

fullcalendar multiple cell select on mobile device?

淺唱寂寞╮ 提交于 2019-12-17 03:16:31
问题 I have created a fullcalendar application for mobile device like Android and iPhone using Phonegap. I am using the Jquery Touch Punch Plugin along with the Jquery fullcalendar plugin. The 'select' method of fullcalendar is working fine on the web. I am able to select multiple cell on the month view of the full calendar on web browser. However, on the native android/iPhone app I am not able to select multiple cell(range of dates) of the calendar. All that happens is when I click on the cell to

Selecting multiple classes with jQuery

浪尽此生 提交于 2019-12-17 02:58:47
问题 I’ve had a good look and can’t seem to find out how to select all elements matching certain classes in one jQuery selector statement such as this: $('.myClass', '.myOtherClass').removeClass('theclass'); Any ideas on how to achieve this? The only other option is to do $('.myClass').removeClass('theclass'); $('.myOtherClass').removeClass('theclass'); But I’m doing this with quite a few classes, so it requires much code. 回答1: This should work: $('.myClass, .myOtherClass').removeClass('theclass')

How to change css display none or block property using Jquery?

巧了我就是萌 提交于 2019-12-17 02:54:09
问题 How to change css display none or block property using Jquery? 回答1: The correct way to do this is to use show and hide : $('#id').hide(); $('#id').show(); An alternate way is to use the jQuery css method: $("#id").css("display", "none"); $("#id").css("display", "block"); 回答2: There are several ways to accomplish this, each with it's own intended purpose. 1 .) To use inline while simply assigning an element a list of things to do $('#ele_id').css('display', 'block').animate(.... $('#ele_id')

What is the fastest method for selecting descendant elements in jQuery?

旧时模样 提交于 2019-12-17 02:52:14
问题 As far is I know, there are a number of ways of selecting child elements in jQuery . //Store parent in a variable var $parent = $("#parent"); Method 1 (by using a scope) $(".child", $parent).show(); Method 2 (the find() method) $parent.find(".child").show(); Method 3 (For immediate children only) $parent.children(".child").show(); Method 4 (via CSS selector) - suggested by @spinon $("#parent > .child").show(); Method 5 (identical to Method 2 ) - according to @Kai $("#parent .child").show(); I

Testing if a checkbox is checked with jQuery

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-17 02:52:10
问题 If the checkbox is checked, then I only need to get the value as 1; otherwise, I need to get it as 0. How do I do this using jQuery? $("#ans").val() will always give me one right in this case: <input type="checkbox" id="ans" value="1" /> 回答1: Use .is(':checked') to determine whether or not it's checked, and then set your value accordingly. More information here. 回答2: $("#ans").attr('checked') will tell you if it's checked. You can also use a second parameter true/false to check/uncheck the

Set selected option of select box

浪尽此生 提交于 2019-12-17 02:33:45
问题 I want to set a option that was selected previously to be displayed on page load. I tried it with the following code: $("#gate").val('Gateway 2'); with <select id="gate"> <option value='null'>- choose -</option> <option value='gateway_1'>Gateway 1</option> <option value='gateway_2'>Gateway 2</option> </select> But this does not work. Any ideas? 回答1: This definitely should work. Here's a demo. Make sure you have placed your code into a $(document).ready : $(function() { $("#gate").val('gateway

JQuery .on() method with multiple event handlers to one selector

不打扰是莪最后的温柔 提交于 2019-12-17 02:33:27
问题 Trying to figure out how to use the Jquery .on() method with a specific selector that has multiple events associated with it. I was previously using the .live() method, but not quite sure how to accomplish the same feat with .on(). Please see my code below: $("table.planning_grid td").live({ mouseenter:function(){ $(this).parent("tr").find("a.delete").show(); }, mouseleave:function(){ $(this).parent("tr").find("a.delete").hide(); }, click:function(){ //do something else. } }); I know I can

jQuery or CSS selector to select all IDs that start with some string [duplicate]

*爱你&永不变心* 提交于 2019-12-17 02:12:06
问题 This question already has answers here : Find html element which id starts with (5 answers) Closed 2 years ago . How can I select all elements whose id starts with "player_"? I have multiple elements like this: <div id="player_290x3dfda">text</div> Every id has a unique stamp on it. How can I select all those elements, either with jQuery or with pure CSS? 回答1: Normally you would select IDs using the ID selector # , but for more complex matches you can use the attribute-starts-with selector