Select a div based on it's child's selector?What is the best way to add options to a select from as a JS object with jQuery?How to get the children of the $(this) selector?How can I know which radio button is selected via jQuery?Creating a div element in jQueryHow can I select an element with multiple classes in jQuery?Get selected text from a drop-down list (select box) using jQueryjquery data selectorjQuery selector for an element that directly contains text?Set select option 'selected', by valuejQuery search for child element, but not with certain div

What is the function of const specifier in enum types?

Can I deep fry food in butter instead of vegetable oil?

Are the Gray and Death Slaad's Bite and Claw attacks magical?

What's the difference between the Find Steed and Find Greater Steed spells?

Family-wise Type I error OLS regression

What verb goes with "coup"?

What is the meaning of "it" in "as luck would have it"?

What could a Medieval society do with excess animal blood?

Enterprise Layers and Naming Conventions

When does it become illegal to exchange bitcoin for cash?

Non-inverting amplifier ; Single supply ; Bipolar input

My players like to search everything. What do they find?

How do I tell my girlfriend she's been buying me books by the wrong author for the last nine months?

ShellExView vs ShellMenuView

What's the idiomatic (or best) way to trim surrounding whitespace from a string?

2019 2-letters 33-length list

Did the Shuttle payload bay have illumination?

Old story where computer expert digitally animates The Lord of the Rings

How does entropy depend on location and scale?

Bootstrap paradox with a time machine in iron

Are the plates of a battery really charged?

Turing Machines: What is the difference between recognizing, deciding, total, accepting, rejecting?

What caused the flashes in the video footage of Chernobyl?

Available snapshots for main net?



Select a div based on it's child's selector?


What is the best way to add options to a select from as a JS object with jQuery?How to get the children of the $(this) selector?How can I know which radio button is selected via jQuery?Creating a div element in jQueryHow can I select an element with multiple classes in jQuery?Get selected text from a drop-down list (select box) using jQueryjquery data selectorjQuery selector for an element that directly contains text?Set select option 'selected', by valuejQuery search for child element, but not with certain div













1















first time long time.
Trying to select certain elements in a feed based on this selector that some of their children contain. The child div (buried way down in divs within divs) in question looks like this:



<div data-test-id="example-test-id">
...
</div>


Their parent divs look like this:



<div data-grid-item="true">
...
</div>


I want to select any div whose data-grid-item="true", who also contains a child div whose data-test-id="example-test-id" .



Resulting in code that looks like this:



$("div[data-grid-item='true']:has(data-test-id="example-test-id"])").css( "background-color", "red" )


In this case I'm just trying to give the parent div a red background so I can verify that I've selected the correct elements, which doesn't seem to be working. As I'm sure you can tell, I'm a novice at jquery so the above code is what I've been able to glean from lots of googling. Any help would be much appreciated.
Thanks!










share|improve this question






















  • your jquery looks right, except for the quotes. You have double quotes around the selector and inside it. Put single quotes around example-test-id.

    – Yuriy Faktorovich
    Mar 25 at 17:37















1















first time long time.
Trying to select certain elements in a feed based on this selector that some of their children contain. The child div (buried way down in divs within divs) in question looks like this:



<div data-test-id="example-test-id">
...
</div>


Their parent divs look like this:



<div data-grid-item="true">
...
</div>


I want to select any div whose data-grid-item="true", who also contains a child div whose data-test-id="example-test-id" .



Resulting in code that looks like this:



$("div[data-grid-item='true']:has(data-test-id="example-test-id"])").css( "background-color", "red" )


In this case I'm just trying to give the parent div a red background so I can verify that I've selected the correct elements, which doesn't seem to be working. As I'm sure you can tell, I'm a novice at jquery so the above code is what I've been able to glean from lots of googling. Any help would be much appreciated.
Thanks!










share|improve this question






















  • your jquery looks right, except for the quotes. You have double quotes around the selector and inside it. Put single quotes around example-test-id.

    – Yuriy Faktorovich
    Mar 25 at 17:37













1












1








1








first time long time.
Trying to select certain elements in a feed based on this selector that some of their children contain. The child div (buried way down in divs within divs) in question looks like this:



<div data-test-id="example-test-id">
...
</div>


Their parent divs look like this:



<div data-grid-item="true">
...
</div>


I want to select any div whose data-grid-item="true", who also contains a child div whose data-test-id="example-test-id" .



Resulting in code that looks like this:



$("div[data-grid-item='true']:has(data-test-id="example-test-id"])").css( "background-color", "red" )


In this case I'm just trying to give the parent div a red background so I can verify that I've selected the correct elements, which doesn't seem to be working. As I'm sure you can tell, I'm a novice at jquery so the above code is what I've been able to glean from lots of googling. Any help would be much appreciated.
Thanks!










share|improve this question














first time long time.
Trying to select certain elements in a feed based on this selector that some of their children contain. The child div (buried way down in divs within divs) in question looks like this:



<div data-test-id="example-test-id">
...
</div>


Their parent divs look like this:



<div data-grid-item="true">
...
</div>


I want to select any div whose data-grid-item="true", who also contains a child div whose data-test-id="example-test-id" .



Resulting in code that looks like this:



$("div[data-grid-item='true']:has(data-test-id="example-test-id"])").css( "background-color", "red" )


In this case I'm just trying to give the parent div a red background so I can verify that I've selected the correct elements, which doesn't seem to be working. As I'm sure you can tell, I'm a novice at jquery so the above code is what I've been able to glean from lots of googling. Any help would be much appreciated.
Thanks!







jquery






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 25 at 17:34









krudsmakrudsma

61 bronze badge




61 bronze badge












  • your jquery looks right, except for the quotes. You have double quotes around the selector and inside it. Put single quotes around example-test-id.

    – Yuriy Faktorovich
    Mar 25 at 17:37

















  • your jquery looks right, except for the quotes. You have double quotes around the selector and inside it. Put single quotes around example-test-id.

    – Yuriy Faktorovich
    Mar 25 at 17:37
















your jquery looks right, except for the quotes. You have double quotes around the selector and inside it. Put single quotes around example-test-id.

– Yuriy Faktorovich
Mar 25 at 17:37





your jquery looks right, except for the quotes. You have double quotes around the selector and inside it. Put single quotes around example-test-id.

– Yuriy Faktorovich
Mar 25 at 17:37










1 Answer
1






active

oldest

votes


















0














It is just a typo, you were so close :



$("div[data-grid-item='true']:has(data-test-id="example-test-id"])")
__________________________________^ Missing '['


Note: The double quotes are also part of the problem you need to replace then by single ones like :



$("div[data-grid-item='true']:has([data-test-id='example-test-id'])")
________________________________________________^_______________^





$("div[data-grid-item='true']:has([data-test-id='example-test-id'])").css("background-color", "red");

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div data-grid-item="true">
<div data-test-id="example-test-id">TEST 1</div>
</div>
<div data-grid-item="true">
<div>TEST 2</div>
</div>
<div data-grid-item="true">
<div data-test-id="example-test-id">TEST 3</div>
</div>








share|improve this answer

























  • If it's just a typo, shouldn't this be voted close due to typo?

    – Huangism
    Mar 25 at 17:40











  • Go ahead and flag it, that doesn't mean not showing the right answer.

    – Zakaria Acharki
    Mar 25 at 17:41











  • Oh I was more on the topic of a typo question should be closed and not answered, yes your answer is most likely correct

    – Huangism
    Mar 25 at 17:42











  • DARN IT! Thanks for the help, it's working now.

    – krudsma
    Mar 25 at 17:46










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55343542%2fselect-a-div-based-on-its-childs-selector%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














It is just a typo, you were so close :



$("div[data-grid-item='true']:has(data-test-id="example-test-id"])")
__________________________________^ Missing '['


Note: The double quotes are also part of the problem you need to replace then by single ones like :



$("div[data-grid-item='true']:has([data-test-id='example-test-id'])")
________________________________________________^_______________^





$("div[data-grid-item='true']:has([data-test-id='example-test-id'])").css("background-color", "red");

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div data-grid-item="true">
<div data-test-id="example-test-id">TEST 1</div>
</div>
<div data-grid-item="true">
<div>TEST 2</div>
</div>
<div data-grid-item="true">
<div data-test-id="example-test-id">TEST 3</div>
</div>








share|improve this answer

























  • If it's just a typo, shouldn't this be voted close due to typo?

    – Huangism
    Mar 25 at 17:40











  • Go ahead and flag it, that doesn't mean not showing the right answer.

    – Zakaria Acharki
    Mar 25 at 17:41











  • Oh I was more on the topic of a typo question should be closed and not answered, yes your answer is most likely correct

    – Huangism
    Mar 25 at 17:42











  • DARN IT! Thanks for the help, it's working now.

    – krudsma
    Mar 25 at 17:46















0














It is just a typo, you were so close :



$("div[data-grid-item='true']:has(data-test-id="example-test-id"])")
__________________________________^ Missing '['


Note: The double quotes are also part of the problem you need to replace then by single ones like :



$("div[data-grid-item='true']:has([data-test-id='example-test-id'])")
________________________________________________^_______________^





$("div[data-grid-item='true']:has([data-test-id='example-test-id'])").css("background-color", "red");

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div data-grid-item="true">
<div data-test-id="example-test-id">TEST 1</div>
</div>
<div data-grid-item="true">
<div>TEST 2</div>
</div>
<div data-grid-item="true">
<div data-test-id="example-test-id">TEST 3</div>
</div>








share|improve this answer

























  • If it's just a typo, shouldn't this be voted close due to typo?

    – Huangism
    Mar 25 at 17:40











  • Go ahead and flag it, that doesn't mean not showing the right answer.

    – Zakaria Acharki
    Mar 25 at 17:41











  • Oh I was more on the topic of a typo question should be closed and not answered, yes your answer is most likely correct

    – Huangism
    Mar 25 at 17:42











  • DARN IT! Thanks for the help, it's working now.

    – krudsma
    Mar 25 at 17:46













0












0








0







It is just a typo, you were so close :



$("div[data-grid-item='true']:has(data-test-id="example-test-id"])")
__________________________________^ Missing '['


Note: The double quotes are also part of the problem you need to replace then by single ones like :



$("div[data-grid-item='true']:has([data-test-id='example-test-id'])")
________________________________________________^_______________^





$("div[data-grid-item='true']:has([data-test-id='example-test-id'])").css("background-color", "red");

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div data-grid-item="true">
<div data-test-id="example-test-id">TEST 1</div>
</div>
<div data-grid-item="true">
<div>TEST 2</div>
</div>
<div data-grid-item="true">
<div data-test-id="example-test-id">TEST 3</div>
</div>








share|improve this answer















It is just a typo, you were so close :



$("div[data-grid-item='true']:has(data-test-id="example-test-id"])")
__________________________________^ Missing '['


Note: The double quotes are also part of the problem you need to replace then by single ones like :



$("div[data-grid-item='true']:has([data-test-id='example-test-id'])")
________________________________________________^_______________^





$("div[data-grid-item='true']:has([data-test-id='example-test-id'])").css("background-color", "red");

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div data-grid-item="true">
<div data-test-id="example-test-id">TEST 1</div>
</div>
<div data-grid-item="true">
<div>TEST 2</div>
</div>
<div data-grid-item="true">
<div data-test-id="example-test-id">TEST 3</div>
</div>








$("div[data-grid-item='true']:has([data-test-id='example-test-id'])").css("background-color", "red");

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div data-grid-item="true">
<div data-test-id="example-test-id">TEST 1</div>
</div>
<div data-grid-item="true">
<div>TEST 2</div>
</div>
<div data-grid-item="true">
<div data-test-id="example-test-id">TEST 3</div>
</div>





$("div[data-grid-item='true']:has([data-test-id='example-test-id'])").css("background-color", "red");

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div data-grid-item="true">
<div data-test-id="example-test-id">TEST 1</div>
</div>
<div data-grid-item="true">
<div>TEST 2</div>
</div>
<div data-grid-item="true">
<div data-test-id="example-test-id">TEST 3</div>
</div>






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 25 at 17:40

























answered Mar 25 at 17:38









Zakaria AcharkiZakaria Acharki

58.1k13 gold badges44 silver badges73 bronze badges




58.1k13 gold badges44 silver badges73 bronze badges












  • If it's just a typo, shouldn't this be voted close due to typo?

    – Huangism
    Mar 25 at 17:40











  • Go ahead and flag it, that doesn't mean not showing the right answer.

    – Zakaria Acharki
    Mar 25 at 17:41











  • Oh I was more on the topic of a typo question should be closed and not answered, yes your answer is most likely correct

    – Huangism
    Mar 25 at 17:42











  • DARN IT! Thanks for the help, it's working now.

    – krudsma
    Mar 25 at 17:46

















  • If it's just a typo, shouldn't this be voted close due to typo?

    – Huangism
    Mar 25 at 17:40











  • Go ahead and flag it, that doesn't mean not showing the right answer.

    – Zakaria Acharki
    Mar 25 at 17:41











  • Oh I was more on the topic of a typo question should be closed and not answered, yes your answer is most likely correct

    – Huangism
    Mar 25 at 17:42











  • DARN IT! Thanks for the help, it's working now.

    – krudsma
    Mar 25 at 17:46
















If it's just a typo, shouldn't this be voted close due to typo?

– Huangism
Mar 25 at 17:40





If it's just a typo, shouldn't this be voted close due to typo?

– Huangism
Mar 25 at 17:40













Go ahead and flag it, that doesn't mean not showing the right answer.

– Zakaria Acharki
Mar 25 at 17:41





Go ahead and flag it, that doesn't mean not showing the right answer.

– Zakaria Acharki
Mar 25 at 17:41













Oh I was more on the topic of a typo question should be closed and not answered, yes your answer is most likely correct

– Huangism
Mar 25 at 17:42





Oh I was more on the topic of a typo question should be closed and not answered, yes your answer is most likely correct

– Huangism
Mar 25 at 17:42













DARN IT! Thanks for the help, it's working now.

– krudsma
Mar 25 at 17:46





DARN IT! Thanks for the help, it's working now.

– krudsma
Mar 25 at 17:46






Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55343542%2fselect-a-div-based-on-its-childs-selector%23new-answer', 'question_page');

);

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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현