Link to home
Start Free TrialLog in
Avatar of Panos
PanosFlag for Germany

asked on

Get id of element - jquery

Hello experts.
I need help to get the id of one input text field by clicking on a span within a label before the field but i can't get it work. Any help?
<!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>Untitled Document</title>
</head>

<body>
<label>Youtube address <span class="checkyoutubelink">Test</span></label>
<input name="youtubelink" id="youtubelink" class="youtubelink" type="text"value="">
</body>
 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
 <script type="text/javascript">
 $('span.checkyoutubelink').click(function(){
	  var tempid = $(this).closest().find('input[type=text]').attr('id');
	  alert(tempid);  
});
 </script>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Panos

ASKER

Hi leakim971
Great! Thank you very much it works
Avatar of Panos

ASKER

Thank you again
regards
panos
'welcome