Reputation: 93
This is the code:
<div id="question" style="float: right">
<a id="score" href="#">
<img id="@Model.QuestionId" src="~/Content/1369264038_arrow_sans_up.png" /></a>
<h4 id="number" style="text-align: center; margin-top: 7px; color: #808080;">
@Model.Score
</h4>
<a href="#">
<img src="~/Content/1369263927_arrow_sans_down.png" /></a>
</div>
I want to know how to select the <h4>
tag here in JQuery?
Note that I am writing function for <a id="score">
:
$("#score").live("click",function(){
var entityId = $(this).children("img").attr("id");
$.getJSON('/Question/Score', { score: 1, entityTypeId: 1, id: entityId }, function (data) {
//here I want to change h4 tag content
});
})
Edit:
I may have some of these h4 tags but I want to select the one after this <a id="score">
.
Upvotes: 1
Views: 1940
Reputation: 168783
Since it has an ID (which should be unique), you don't need to make it relative to the score
element, as you're asking in the question; you can just select it directly: $("#number")
.
But since you've specified that you want it relative to score
, you can use jQuery's .sibling()
method to find it as a sibling of score
:
$score = $('#score');
$h4 = $score.siblings('h4');
Hope that helps.
Upvotes: 0
Reputation: 7944
$("h4")
OR
$("div > h4")
OR
$("div h4")
OR
$("#question div")
OR
$("#question > div")
OR
$("#number")
Upvotes: 1
Reputation: 22812
Well it has its own id, so:
$('#number")
In case you have more h4
around, consider:
$('#question h4')
Upvotes: 4