Solved

Jquery or JavaScript - get the father of element

Posted on 2014-09-08
1
341 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Javascript create file issue 4 48
form button worked now it doesnt anymore 9 42
Randomize in Owl Carousel v1.3.2 6 20
Objects on Same Line 2 18
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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 invoke it on a web page. 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.: (CODE)

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now