views:

42

answers:

3

In the below code onclick edit how can the value of tag test be obtained in the edit function.

<script>
function edit(a) 
{

} 
var a=     <tr class="clickable"><td id="userval" BGCOLOR="#FF6699"><label id="test">' + a + '</lable>&nbsp;&nbsp;&nbsp; <IMG SRC="edit.gif" onclick="javascript:edit(test.value);" > ></td></tr>
</script>

Thanks.

+1  A: 

I take it a is actually a string? (it's not in your example, but it's concatenated as though it were)

function edit(a) 
{
    var value = $(a).find('#test').text();
}
David Hedlund
+1  A: 
var value = $("#test", $(a)).text()
SMiX
+1  A: 

Assuming jQuery usage:

<script>
function edit(elem) 
{
   $(elem).siblings('label#test').html();
} 

var a= '<tr class="clickable"><td id="userval" BGCOLOR="#FF6699"><label id="test">' + a + '</label>&nbsp;&nbsp;&nbsp; <IMG SRC="edit.gif" onclick="javascript:edit(this);" > ></td></tr>
</script>
Marcin
and how to set this to some other value?
Hulk
what you mean by some other values? .text() .atr() ? cheers
Marcin