Solved

Jquery or JavaScript - get the father of element

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to create an extensible mechanism for linked drop downs.
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)
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…

760 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

23 Experts available now in Live!

Get 1:1 Help Now