?
Solved

Get id of element - jquery

Posted on 2014-09-30
4
Medium Priority
?
129 Views
Last Modified: 2014-09-30
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

0
Comment
Question by:Panos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 40352721
test page : http://jsfiddle.net/42qy2m3z/

$('span.checkyoutubelink').click(function(){
	  var tempid = $(this).closest("label").next('input[type=text]').attr('id');
	  alert(tempid);  
});

Open in new window

0
 
LVL 2

Author Comment

by:Panos
ID: 40352727
Hi leakim971
Great! Thank you very much it works
0
 
LVL 2

Author Closing Comment

by:Panos
ID: 40352728
Thank you again
regards
panos
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40352744
'welcome
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
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…
Suggested Courses

752 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