简体   繁体   中英

jQuery find element with class name and attribute value

Haven't come up with much as far as documentation goes. How do I find an element with a particular class name that also has a specified attribute value.?

function go_to_page(page){
    $('.page_link[longdesc=page]').addClass('.active_page'); 
}

I got the example from here . Tried testing it myself and it didn't seem to work.

function go_to_page(page){

    $('.page_link[longdesc=' + page + ']').addClass('active_page'); 

}

You have some errors in your syntax, try:

 function go_to_page(page){

     $('.page_link[longdesc='+page+']').addClass('active_page'); 
 }

classes normally don't start with a dot (only in the selector not the name)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM