I'm trying to set the background colour of a span using jquery. I've used all functions in the title and all give me an error:
SCRIPT438: Object doesn't support property or method 'css'/'attr'/'addClass'
Any idea how I can solve this? All I want is to change the bg colour however I prefer if I can set the class.
code:
var liList = ul.find('li span');
        $.each(liList, function(index, value){
            if(value.innerText == currPage){
                value.css('background-color', '#D94A38');
            }
        });
                The each() function gives you DOM object not jQuery object 
Change to
$(value).css('background-color', '#D94A38');
Your code would be
var liList = ul.find('li span');
    $.each(liList, function(index, value){
        if(value.innerText == currPage){
            $(value).css('background-color', '#D94A38');
        }
});
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With