Apply selector to elements that have already been selected
up vote
0
down vote
favorite
I feel like I am asking something really dumb but perhaps it's not my day. If I have a selected element already, e.g:
let tables = $('table');
But now I want to apply another selector like .some-class on top of those tables, but without creating a new jQuery object like this
$('table.some-class')
How would I do it?
javascript jquery html jquery-selectors
add a comment |
up vote
0
down vote
favorite
I feel like I am asking something really dumb but perhaps it's not my day. If I have a selected element already, e.g:
let tables = $('table');
But now I want to apply another selector like .some-class on top of those tables, but without creating a new jQuery object like this
$('table.some-class')
How would I do it?
javascript jquery html jquery-selectors
May be like$(tables+'.some-class');
– Ayaz Shah
Nov 22 at 12:57
1
What aboutfind()
– Ankit Agarwal
Nov 22 at 12:58
@AnkitAgarwal$('table').find('.some-class')is not the same than$('table.some-class').
– dabadaba
Nov 22 at 13:16
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I feel like I am asking something really dumb but perhaps it's not my day. If I have a selected element already, e.g:
let tables = $('table');
But now I want to apply another selector like .some-class on top of those tables, but without creating a new jQuery object like this
$('table.some-class')
How would I do it?
javascript jquery html jquery-selectors
I feel like I am asking something really dumb but perhaps it's not my day. If I have a selected element already, e.g:
let tables = $('table');
But now I want to apply another selector like .some-class on top of those tables, but without creating a new jQuery object like this
$('table.some-class')
How would I do it?
javascript jquery html jquery-selectors
javascript jquery html jquery-selectors
edited Nov 22 at 13:03
Mohammad
14.1k93259
14.1k93259
asked Nov 22 at 12:56
dabadaba
3,06564086
3,06564086
May be like$(tables+'.some-class');
– Ayaz Shah
Nov 22 at 12:57
1
What aboutfind()
– Ankit Agarwal
Nov 22 at 12:58
@AnkitAgarwal$('table').find('.some-class')is not the same than$('table.some-class').
– dabadaba
Nov 22 at 13:16
add a comment |
May be like$(tables+'.some-class');
– Ayaz Shah
Nov 22 at 12:57
1
What aboutfind()
– Ankit Agarwal
Nov 22 at 12:58
@AnkitAgarwal$('table').find('.some-class')is not the same than$('table.some-class').
– dabadaba
Nov 22 at 13:16
May be like
$(tables+'.some-class');– Ayaz Shah
Nov 22 at 12:57
May be like
$(tables+'.some-class');– Ayaz Shah
Nov 22 at 12:57
1
1
What about
find()– Ankit Agarwal
Nov 22 at 12:58
What about
find()– Ankit Agarwal
Nov 22 at 12:58
@AnkitAgarwal
$('table').find('.some-class') is not the same than $('table.some-class').– dabadaba
Nov 22 at 13:16
@AnkitAgarwal
$('table').find('.some-class') is not the same than $('table.some-class').– dabadaba
Nov 22 at 13:16
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
You need to use .filter() to adding filter to variable selector.
let tables = $('table');
tables = tables.filter('.some-class');
tables.css('color', 'red');<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>table</td>
</tr>
</table>
<table class="some-class">
<tr>
<td>table has .some-class</td>
</tr>
</table>add a comment |
up vote
0
down vote
With the following code you would find all elements with class .some-class under the elements with tag name table.
let tables = $('table').find('.some-class');
Of course, it is just for the example, otherwise you can simply do:
let tables = $('table .some-class');
In your question it is not clear if you want children elements or just filter the elements. If you want the tables with a given class, you would do:
let tables = $('table').filter('.some-class');
I never mentioned children elements. I am trying to apply the selector on the original element.
– dabadaba
Nov 22 at 13:14
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You need to use .filter() to adding filter to variable selector.
let tables = $('table');
tables = tables.filter('.some-class');
tables.css('color', 'red');<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>table</td>
</tr>
</table>
<table class="some-class">
<tr>
<td>table has .some-class</td>
</tr>
</table>add a comment |
up vote
1
down vote
accepted
You need to use .filter() to adding filter to variable selector.
let tables = $('table');
tables = tables.filter('.some-class');
tables.css('color', 'red');<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>table</td>
</tr>
</table>
<table class="some-class">
<tr>
<td>table has .some-class</td>
</tr>
</table>add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You need to use .filter() to adding filter to variable selector.
let tables = $('table');
tables = tables.filter('.some-class');
tables.css('color', 'red');<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>table</td>
</tr>
</table>
<table class="some-class">
<tr>
<td>table has .some-class</td>
</tr>
</table>You need to use .filter() to adding filter to variable selector.
let tables = $('table');
tables = tables.filter('.some-class');
tables.css('color', 'red');<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>table</td>
</tr>
</table>
<table class="some-class">
<tr>
<td>table has .some-class</td>
</tr>
</table>let tables = $('table');
tables = tables.filter('.some-class');
tables.css('color', 'red');<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>table</td>
</tr>
</table>
<table class="some-class">
<tr>
<td>table has .some-class</td>
</tr>
</table>let tables = $('table');
tables = tables.filter('.some-class');
tables.css('color', 'red');<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>table</td>
</tr>
</table>
<table class="some-class">
<tr>
<td>table has .some-class</td>
</tr>
</table>answered Nov 22 at 13:00
Mohammad
14.1k93259
14.1k93259
add a comment |
add a comment |
up vote
0
down vote
With the following code you would find all elements with class .some-class under the elements with tag name table.
let tables = $('table').find('.some-class');
Of course, it is just for the example, otherwise you can simply do:
let tables = $('table .some-class');
In your question it is not clear if you want children elements or just filter the elements. If you want the tables with a given class, you would do:
let tables = $('table').filter('.some-class');
I never mentioned children elements. I am trying to apply the selector on the original element.
– dabadaba
Nov 22 at 13:14
add a comment |
up vote
0
down vote
With the following code you would find all elements with class .some-class under the elements with tag name table.
let tables = $('table').find('.some-class');
Of course, it is just for the example, otherwise you can simply do:
let tables = $('table .some-class');
In your question it is not clear if you want children elements or just filter the elements. If you want the tables with a given class, you would do:
let tables = $('table').filter('.some-class');
I never mentioned children elements. I am trying to apply the selector on the original element.
– dabadaba
Nov 22 at 13:14
add a comment |
up vote
0
down vote
up vote
0
down vote
With the following code you would find all elements with class .some-class under the elements with tag name table.
let tables = $('table').find('.some-class');
Of course, it is just for the example, otherwise you can simply do:
let tables = $('table .some-class');
In your question it is not clear if you want children elements or just filter the elements. If you want the tables with a given class, you would do:
let tables = $('table').filter('.some-class');
With the following code you would find all elements with class .some-class under the elements with tag name table.
let tables = $('table').find('.some-class');
Of course, it is just for the example, otherwise you can simply do:
let tables = $('table .some-class');
In your question it is not clear if you want children elements or just filter the elements. If you want the tables with a given class, you would do:
let tables = $('table').filter('.some-class');
answered Nov 22 at 12:58
LaurentG
7,86573553
7,86573553
I never mentioned children elements. I am trying to apply the selector on the original element.
– dabadaba
Nov 22 at 13:14
add a comment |
I never mentioned children elements. I am trying to apply the selector on the original element.
– dabadaba
Nov 22 at 13:14
I never mentioned children elements. I am trying to apply the selector on the original element.
– dabadaba
Nov 22 at 13:14
I never mentioned children elements. I am trying to apply the selector on the original element.
– dabadaba
Nov 22 at 13:14
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431547%2fapply-selector-to-elements-that-have-already-been-selected%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
May be like
$(tables+'.some-class');– Ayaz Shah
Nov 22 at 12:57
1
What about
find()– Ankit Agarwal
Nov 22 at 12:58
@AnkitAgarwal
$('table').find('.some-class')is not the same than$('table.some-class').– dabadaba
Nov 22 at 13:16