Solved

Jquery or JavaScript - get the father of element

Posted on 2014-09-08
1
346 Views
Last Modified: 2014-09-08
Hi E's,
I need help to get a father of element.
I try this code in Jquery:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>pai do elemento em jquery</title> 
<script src="../../ficheiros_apoio/jquery.min.js"></script>
</head> 
<body> 
<div id="pai">
<div class="filho">eu sou o filho</div>
</div>
<script>
var info = $(".filho").parent();
$.each(info, function( index, value ) {
  alert( index + ": " + value );
});

</script>
</body> 
</html> 

Open in new window

But not work.
What is the solution for get the Id "pai"?

The best regards, JC
0
Comment
Question by:Pedro Chagas
1 Comment
 
LVL 38

Accepted Solution

by:
Tom Beck earned 500 total points
ID: 40309684
value.id
var info = $(".filho").parent();
$.each(info, function( index, value ) {
  alert( index + ": " + value.id );
});

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question