<div class="activity" id="4">
<div class="activity" id="3">
<div class="activity" id="2">
<div class="activity" id="1">
and jquery code to find first id
var ID = $('.activity:first').attr('id');
whats wrong there? error in firebug
Warnung: Unbekannte P开发者_开发问答seudoklasse oder Pseudoelement 'first'. Zeile: 0
thank you
One thing that is wrong is that your ids need to start with a letter. Numeric only ids are not legal HTML. The selector looks ok otherwise, so I'm not sure why you would be getting that error. Are you sure you are including jQuery and no other javascript libraries?
Make sure you close your DIVs. To get the first div id, You can also do
var ID = $('.activity').eq(0).attr('id');
Nothing seems to be wrong.
I can use your exact markup/jquery and it works just fine:
http://jsfiddle.net/6AH6T/
You might like to try tidying up your HTML and seeing if that helps - e.g. closing your DIVs, and specifying valid IDs.
Otherwise you could try other ways of getting the ID:
var ID = $('.activity').first().attr('id');
However I really don't think your issue is with the jQuery snippet you posted. If you supply us with some more context we might be able to help more.
精彩评论