Jq failed to get operation element?

clipboard.png

clipboard.png

clipboard.png

I want to determine whether the display of the element named db1 under the dt under each Li is none when clicking the button. If the whole Li is hidden, how should I write an error? Ask the seniors to pass by for advice! Thank you


jQ is compatible with getting native DOM objects in the form of $('- sharpuls li') [1] . After you write this, you return the native DOM object, while the native DOM object does not have the .children () method. So you need to change the subsequent array element reference to .eq (1) , that is, $('- sharpuls li'). Eq (1) , so that the jQ object is returned so that you can call the jQ method normally.


you can try $("- sharpuls li"). Eq (1)


$(function(){
    $('-sharpbtn').click(function(){

        for(var i = 0 ; i<$('-sharpuls li').length ; iPP){
            var s = $('-sharpuls li').eq(i).find('.db1');
            if(s.css('display') == 'none'){
                $('-sharpuls li').eq(i).css('display','none')
            }
        }
    })
})

that's because $("- sharpuls li") [I] converts the jq object into a dom object and changes it to $("- sharpuls li") .eq (i) should be fine


.

what you get with $('- sharpuls li') [1] is a native js object, not a jquery object.
the reason for saving is obvious. Of course, the native object will report an error when calling the jquery method.
reference code
`$ ('- sharpbtn') .click (function () {

             $('.db1').each(function(i){
                 if($('.db1').eq(i).css('display')=='none'){
                     $('.db1').eq(i).parent().parent().hide();
                 }
             })
         })`

console.log($("-sharpuls li")[1].children[0].children[1]);
$("-sharpuls li")[1].children[0].children[1].style.color="red";

I'm doing it again. [style= "display:none"] this part looks so strange, if you can change this thing to class . It will probably feel better

.
$('-sharpuls .dbl[style="display:none"]').parent('li').hide();

$(obj) .eq (1). This will do


< H2 > mixed writing of JS and JQ: < / H2 >
js followed by the jq method is very simple $(jsDOm object)
jq object followed by the js method $('tag'). Get (0) or $(' tag') [0]
The

JQ object can only use the JQ method
native DOM object, and the native method


$('- sharpuls li') [1] is equivalent to converting the jq object into a native DOM object. $('- sharpuls li'). Eq (1) returns a jq object before the jq method can be called.

Menu