How to target the parent div from child div?

Let’s learn how to target the parent div from child div. The most accurate or helpful solution is served by Stack Overflow.

There are ten answers to this question.

Best solution

How to target & alter child element by tag with only the parent div id?

Using regular JavaScript (or prototype), I'm trying to alter the href attribute of the first and only anchor tag within a div to include a query string at the end with windows.location.search. The div has an id, while the anchor is classless and id-less. I've seen similar code elsewhere, but its not quite right. What I have so far is below: var divTag = document.getElementById("DivId").getElementsByTagName("a"); for(i = 0; i < divTag.length; i++){ divTags[i].href = "...

Answer:

You declare the variable as divTag but set the attribute as divTags.

Read more

SFox at Stack Overflow Mark as irrelevant Undo

Other solutions

What are some ways to create an HTML container which expands width with each added child - all in one row?

How to force parent to expand with children width. HTML:     <div class="parent">         <div class="child">             1         </div>         <div class="child">             2       ...

Answer:

This can be achieved by styling divs to act as tables, rows and cells. Your parent div is set to display...

Read more

Dwayne Charrington at Quora Mark as irrelevant Undo

jQuery: How can I find the ID attribute of a parent element with a particular class name from a child element?

I tried like this but the variable id is always empty. <div id="banana" class="fruit"> <div> <p>some text</p> </div> </div> <div id="apple" class="fruit"...

Answer:

You have to walk the DOM to the closest <div/> with the class "fruit" and get the...

Read more

Matteo Canu at Quora Mark as irrelevant Undo

Using XPath, how can I select a block that contains a specific child element?

I have several divs setup with the same class name, 'info'. Each div has an h2 element in it with a unique value. For example, the text of one h2 is 'About'. I want to be able to select the parent div based on the content of its child h2 tag, so that...

Answer:

//h2[contains(., 'about')]/../p

Read more

Demitry ҈ ҈ ҈ ҈ Sky at Quora Mark as irrelevant Undo

How, in CSS, can one target an element only when it is the parent of another specific element?

Example: <div>      <input type="checkbox"> </div> I want the div to have a different background color when the checkbox is checked, and when it is not checked. To clarify, I am looking for a selector to replace what...

Answer:

You can't, you have to use JS to do this.  This was actually proposed to the CSS Working Group but they...

Read more

Mark Vilrokx at Quora Mark as irrelevant Undo

Need CSS Help - Child 2px lower than Parent?

Hi I have the following CSS: table.user3_pill { margin-top: 0; margin-bottom: 0; margin-left: auto; margin-right: auto; padding: 0; } td.user3_pill_l { background: url(../images/style/user3_pill_l.png) no-repeat; width: 10px; height: 16px; margin: 0...

Answer:

I couldn't duplicate your problem because I don't have the images but I can think of one reason. It...

Read more

Richard at Yahoo! Answers Mark as irrelevant Undo

Is a DIV the parent of a paragraph <p> in CSS?

Subject says all. In CSS is the Div the Parent and the paragraph <p> the child? Or am I understanding this incorrectly.

Answer:

If the <p> is inside the <div>, then that is correct.

Read more

beausife... at Yahoo! Answers Mark as irrelevant Undo

Do I put 1099-DIV on my tax return or my child's tax return?

We have about 30-40k agi and my son, 7-5K agi He has received $44 in dividends from pepsico stock from a custodial account and received a 1099-DIV with the title "Parent ...show more

Answer:

If his only unearned income is $44 in dividends and the rest of his income is from wages, he should...

Read more

VU47R4FELJWFD3DWUXGXRKDU3U at Yahoo! Answers Mark as irrelevant Undo

An odesk contractor appears to have added a script to my site.  I want to be fair, is there any way this is a mistake?

He was modifying an existing site.  The site he created caused several words on my page to appear hyperlinked and when you moused over a little advertising window appeared.  My site did NOT do this before.  I commented out a script that was not on the...

Answer:

data.htm is an entry point and run.js contains the actual code to add underlined ads as well as what...

Read more

Deep Joy Majumdar at Quora Mark as irrelevant Undo

How do I insert an Element after another Element using Mootools?

For example, if I have the following piece of HTML: <div id="myParent">     <div id="myFirstElement" /> </div> I want the result to look like the following: <div id="myParent">     <div...

Answer:

new Element('div', {id: 'mySecondElement'}).inject('myFirstElement', 'after'); You can find documentation...

Read more

Sylvain Robez-Masson at Quora Mark as irrelevant Undo

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.