0

I have a list of checkboxes and want to do something with all the names of the checkboxes. But I can't seem to access the HTML objects:

$('.update').click(function(){
                $('input[type=checkbox]:checked').each(function(i,elem){
                    console.log(elem);
                    elem.hide();
                });
            });

This produces TypeError: elem.hide is not a function

But the console.log(elem) shows: <input type="checkbox" name="TV">

How can I access each element?

2 Answers 2

3

You are accessing the DOM node directly by using elem. You need to pass it to $() to get a jQuery object with access to .hide() and other jQuery methods:

$('.update').click(function() {
  $('input[type=checkbox]:checked').each(function(i, elem) {
    $(elem).hide();
  });
});

Sign up to request clarification or add additional context in comments.

Comments

1

elem is DOM element, not jquery type. You can use $(elem).hide() instead

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.