jquery-selectors

How to filter undesired elements with jQuery

断了今生、忘了曾经 提交于 2019-12-23 12:46:30
问题 lets take for example two divs, <div class="main right"></div> <div class="main"></div> And this jQuery snippet, as it follows: $('.main').css('background-color','red'); This will change both divs background-color to red, as normal. I'd like to know how to change that color for the divs that have only "main" as class, not "main right", 回答1: $('.main:not(.right)').css('background-color','red'); Or: $('.main').not('.right').css('background-color','red'); If had to more complicated conditions it

Selecting all the divs with png background-image

半城伤御伤魂 提交于 2019-12-23 12:36:35
问题 How can I select in jQuery all the div s that have background-image: url(somepath/somename.png) in their style? 回答1: There isn't a jQuery selector, but this might work: $('div').each( function() { if ( $(this).css('background-image') == 'url("image.png")' ) { // do something here } }); However, a more efficient method would be to make sure you only have a single class that uses that background image, then simply select $('.bgClass') 回答2: Try adding a custom selector: $(document).ready

How to delay the Execution of a Javascript Function After a Live Keyup event is called?

和自甴很熟 提交于 2019-12-23 11:35:15
问题 Hey programmers, I have removed everything from my function below to just target exactly what I need help with... After the keyup event is called, the reloadContent function will make an ajax call to gather new data from a database. Only problem is, my servers are overloading because there is no delay from the keyup events, after every keyup the function is called. I need a way to delay, say 1 second, before the reloadContent function is called. This way it will not run 4 times (when the user

How to delay the Execution of a Javascript Function After a Live Keyup event is called?

巧了我就是萌 提交于 2019-12-23 11:35:03
问题 Hey programmers, I have removed everything from my function below to just target exactly what I need help with... After the keyup event is called, the reloadContent function will make an ajax call to gather new data from a database. Only problem is, my servers are overloading because there is no delay from the keyup events, after every keyup the function is called. I need a way to delay, say 1 second, before the reloadContent function is called. This way it will not run 4 times (when the user

jQuery - How to select last column of all rows in a table?

喜夏-厌秋 提交于 2019-12-23 11:14:50
问题 Assuming I have a HTML table as follows (with the appropriate tr, td tags): a1 | b1 | c1 a2 | b2 | c2 a3 | b3 | c3 a4 | b4 | c4 <table border="1"> <tr> <td>a1</td> <td>b1</td> <td>c1</td> </tr> <tr> <td>a2</td> <td>b2</td> <td>c2</td> </tr> <tr> <td>a3</td> <td>b3</td> <td>c3</td> </tr> <tr> <td>a4</td> <td>b4</td> <td>c4</td> </tr> </table> I'm trying to select all the c* rows to perform an action on them. Using the $('td:last') selector just selects the last td tag, i.e., c4. I tried $('tr

jQuery - How to select last column of all rows in a table?

左心房为你撑大大i 提交于 2019-12-23 11:14:23
问题 Assuming I have a HTML table as follows (with the appropriate tr, td tags): a1 | b1 | c1 a2 | b2 | c2 a3 | b3 | c3 a4 | b4 | c4 <table border="1"> <tr> <td>a1</td> <td>b1</td> <td>c1</td> </tr> <tr> <td>a2</td> <td>b2</td> <td>c2</td> </tr> <tr> <td>a3</td> <td>b3</td> <td>c3</td> </tr> <tr> <td>a4</td> <td>b4</td> <td>c4</td> </tr> </table> I'm trying to select all the c* rows to perform an action on them. Using the $('td:last') selector just selects the last td tag, i.e., c4. I tried $('tr

Copy the contents of one column to another in jQuery

旧城冷巷雨未停 提交于 2019-12-23 10:19:50
问题 The following jQuery is extremely slow (~7 sec). I'm clearly doing it the wrong way! I'm trying to copy the contents of column col to column 0 in an HTML table so if col is 2, then I need to copy column 2 to column 0. for (var i=0;i<31;i++) $('.grid tr:nth-child(' + i + ') td:first-child').text( $('.grid tr:nth-child(' + i + ') td:nth-child(' + col + ')').text() ); HTML: <table> <tr><td>A</td><td>D</td><td>G</td></tr> <tr><td>B</td><td>E</td><td>H</td></tr> <tr><td>C</td><td>F</td><td>I</td><

jquery find text inside <td>

徘徊边缘 提交于 2019-12-23 10:07:36
问题 I'm playing around with some selectors, and I'm hitting a wall with selecting Text inside a cell. Here's a simple attempt I'm making. <table> <tr> <td>First Name</td> <td>*required</td> </tr> </table> I want to change the class for that cell to be "red" - if the string "*required" is found. Here's my attempt at the jquery: $("td:contains('*required')").addClass("red"); It's causing all cells to apply that class, it seems. Any better ways to look for specific text? 回答1: What you have works,

jQuery, use ~ as a part of id - how?

隐身守侯 提交于 2019-12-23 09:53:45
问题 In my application I have a form, which elements are named using a certain convention, i.e. they are paths, the parts of which are separated using the ~ sign. Now I need to access one of them in jQuery by id, but I fail. Apparently, jQuery treats it as the #prev ~ sibling thing. Is there a way I can sort of escape the ~ sign in the jQuery function? Here is an example of what my code looks like: <select id="a~b~c"> <option value='1'>one</opiton> </select> <script> $("#a~b~c").change(function(){

How to select elements with the same attribute value in jQuery?

孤街醉人 提交于 2019-12-23 09:34:49
问题 Say I have a structure like so: <div data-stuff="foo"></div> <div data-stuff="foo"></div> <div data-stuff="foo"></div> <div data-stuff="bar"></div> <div data-stuff="bar"></div> <div data-stuff="bar"></div> <div data-stuff="baz"></div> And I want to hide all the divs with the same attribute except the first, so I'd get: <div data-stuff="foo"></div> <div data-stuff="bar"></div> <div data-stuff="baz"></div> Now I know I could just do this: $('[data-stuff=foo]:gt(0), [data-stuff=bar]:gt(0), [data