Hulk
Hulk

Reputation: 34160

Getting value of another tag

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>

Upvotes: 0

Views: 90

Answers (3)

Marcin
Marcin

Reputation: 5579

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>

Upvotes: 1

Andrey Kuznetsov
Andrey Kuznetsov

Reputation: 11830

var value = $("#test", $(a)).text()

Upvotes: 1

David Hedlund
David Hedlund

Reputation: 129792

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();
}

Upvotes: 1

Related Questions