Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
6
rated 0 times [  10] [ 4]  / answers: 1 / hits: 106108  / 14 Years ago, mon, august 2, 2010, 12:00:00

I have a page with several div's. All of the divs have a unique id. I would like to send that id to a javascript function. I have tried to save it as a value as well, and send this.value, but that does not work either.



<div class='recordElem$val' id='$rname' value='$rname'
onclick='javascript:updateRecord(this.value);'>
$name</div>

More From » html

 Answers
96

Here is a jQuery answer



  <script type=text/javascript src=js/jquery-1.4.2.min.js></script>

<script type=text/javascript>
function clicked(item) {
alert($(item).attr(id));
}
</script>


<div onclick=clicked(this); id=test>test</div>

[#96049] Thursday, July 29, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
arthur

Total Points: 729
Total Questions: 107
Total Answers: 109

Location: China
Member since Mon, Aug 22, 2022
2 Years ago
;