Reputation: 227
I trying as a beginner in JS to get the specific innerHTML that clicked from the options. they have the same class so this is the real problem. how can i "point" to specific class the been clicked in var vup?
my code:
<script>
$(function() {
$(".up").click(function () {
var vup=document.getElementsByClassName("up").innerHTML;
var qid=document.getElementsByName("id").value;
document.getElementById("sadas").innerHTML=qid+"<br>"+vup;
});
});
</script>
<input name="id" value="5" type="hidden">
<a class="up" title="אם אתה מתחרט על הצבעה זו.">vote up</a>
<b>0</b>
<a class="up" title="אם שאלה זו שטוחה או פוגענית או חוזרת על עצמה או פשוטה." style="background-position:0 -220px;">vote down</a>
<div id="sadas">sda</div>
Upvotes: 1
Views: 33
Reputation: 2275
use $(this) inside your click function
$('.up').click(
function() {
$(this).html('this will apply only to the specific .up class that is clicked, no matter how many .up class you declare');
}
);
than you can use $(this).closest('')
or .next()
or other tree traversal to get to the desired dom you want to manipulate.
Upvotes: 2
Reputation: 364
In jQuery that's
$(.up).click(function(event) {
var text = $(event.target).text();
})
;
Upvotes: 0