如何在这里选择h4标签?

时间:2013-05-24 12:07:00

标签: jquery

这是代码:

<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>

我想知道如何在JQuery中选择<h4>标记? 请注意,我正在编写<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
        });
    })

编辑: 我可能有一些h4标签,但我想在<a id="score">之后选择一个。

4 个答案:

答案 0 :(得分:4)

它有自己的ID,所以:

$('#number")

如果您有更多h4,请考虑:

$('#question h4')

答案 1 :(得分:1)

$("h4")
OR
$("div > h4")
OR
$("div h4")
OR
$("#question div")
OR
$("#question > div")
OR
$("#number")

答案 2 :(得分:0)

因为它有一个ID(应该是唯一的),所以你不需要相对于score元素,因为你在问题中提问;你可以直接选择它:$("#number")

但是既然您已经指定相对于score,那么您可以使用jQuery的.sibling() method将其作为score的兄弟:

$score = $('#score');
$h4 = $score.siblings('h4');

希望有所帮助。

答案 3 :(得分:0)

使用此:

var h4 = $('h4#number');
相关问题