开发者

Can you select an element with two classes in jQuery

I have an element that has two classes but can't seem to select it with jQuery. Is it possible. Here's the code:

<html>
<head runat="server">
    <script type="text/javascript" src="abc/scripts/jquery-1.4.2.min.js"></script>

    <script type="text/javascript">

      $(document).ready(function() {
        alert($(".x.y").html()); //shows null, I want it to show "456"
      });

    </script>

</head>

<body>

<div class="x" class"y开发者_如何学编程">456</div>

</body>
</html>


Having two class attributes isn't valid SGML (therefore HTML), as far as I'm aware. Try this:

<div class="x y">456</div>


You should be able to target dual classes like so:

$(document).ready(function() {
    alert($(".x.y").html()); //shows null, I want it to show "456"
});

with html like this:

<div class="x y">456</div>


This

<div class="x" class"y">456</div>

is incorrect, change it to

<div class="x y">456</div>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜