views:

78

answers:

3

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>
+5  A: 

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

<div class="x y">456</div>
Chris Smith
+4  A: 

This

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

is incorrect, change it to

<div class="x y">456</div>
Ben
+3  A: 

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