Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

180
Visualizações
Recursively disabling all children of an element

This might be a yes/no type of question.

I'm trying to disable absolutely all children of an element in jquery.

Does calling

$('#id_of_an_element').children().do(function(){
    do_something;
});

recursively call all children of an element, or does it just do_something to all the direct descendants of an_element?

Help is appreciated,

Josh

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Given a jQuery object that represents a set of DOM elements, the .children() method allows us to search through the immediate children of these elements in the DOM tree and construct a new jQuery object from the matching elements. The .find() and .children() methods are similar, except that the latter only travels a single level down the DOM tree. Note also that like most jQuery methods, .children() does not return text nodes; to get all children including text and comment nodes, use .contents().

http://api.jquery.com/children/

You can do this if you want to act on all descendants at any level of nesting:

$('#id_of_an_element').find('*').attr('disabled', true);

or using the descendant selector:

$('#id_of_an_element *').attr('disabled', true);
over 4 years ago · Santiago Trujillo Relatório

0

Since you want to affect all descendants, just do this:

$('#id_of_an_element *').each(function() {
    // do something
});

But I'd be curious to know what exactly you're doing.

The disabled property is meaningless for many element types. It could be that whatever you're doing will benefit from the inheritance of CSS.

Or if you actually want the disabled property, then you might as well just target form elements.

$('#id_of_an_element :input').attr('disabled','disabled');
over 4 years ago · Santiago Trujillo Relatório

0

You can do

function disableChildren(obj) {
    obj.children().each(function(i, val) {
         disable(val);
         disableChildren(val);
    });
}

disableChildren($("#id"));

See .each There doesn't appear to be a .do method.

You'll have to implement disable as a function to do what every you want when you say "disable"

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda