I got this line in my script, which check the items class:
$('#post').attr('class');
Is there a chance, to read it like:
$('#post*').attr('class');
So if the ID will be fe. post405
it will still read this?
I've checked it and it won't work with *
, so so there any other way t开发者_开发知识库o read items this way?
$('[id^=post]').attr('class');
You're looking for the [attribute^=*]
selector.
It sounds like you're doing a class based search on the id. This is really not the recommended way to do this. The more "proper" way would be to add a "post" class to your elements and look for
$('.post')
of course, if you're looking for the class attribute, there's a lot you can do with that too... using the attr()
function for that is probably not what you want.
jQuery already provides a "starts with" selector for this purpose.
http://api.jquery.com/attribute-starts-with-selector/
$('[id^="post"]').attr('class');
精彩评论