We help IT Professionals succeed at work.
Get Started

Problem: Using jquery's ".live" within an ".each" loop

the_sleeper asked
Last Modified: 2012-05-11

I've set up a little test to learn how to use jquery's .live options.

3 hard-coded radio buttons
1 dynamic radio button
Test the click event

After several attempts at using live...all failed. Using .bind() works, but not on the dynamic field ((see code below)) .  How should this script be adapted to use the jquery .live() method?

<!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">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready(function() {

					alert("index: " + index + " value = " + $(this).val())	
			) // end bind
		} // end function
	) // end each
	// dynamic field test
	$('<input type="radio" name="rdo_test" value="4" />Test 4<br />').appendTo('body');


<input type="radio" name="rdo_test" value="1" />Test 1<br />
<input type="radio" name="rdo_test" value="2" />Test 2<br />
<input type="radio" name="rdo_test" value="3" />Test 3<br />


Open in new window

Watch Question
Expert of the Year 2008
Top Expert 2008
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE