Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

182
Vistas
How to make columns with collapsible ul and li tags dynamically?

I am currently using the following two functions to dynamically create a collapsible list from an object which contains info on the individual parts within the object. I have also included a checkbox for each item in the collapsible list, but that check box always appears right next to the names. I would prefer these checkboxes to be in the same row as the list item, but in a separate column so that it looks neater. I might also add more columns later on with material info. So I was trying to figure out how I can do this with my current setup below or if there was a better way to achieve what I want instead of using my list.

<div class="objtree"></div>
function check(obj) {
    var html = '';
    var name = obj.name ? obj.name +' (' +obj.type+')' : obj.type;
    html +='<div class="node">'
    html += '<li class="ntitle">' + name + '<input type="checkbox" name="'+(obj.id-id)+'" value="checked" onchange="snap(this)"/></li>';

    if (obj.children) {
        html += '<ul class="children hide">';
        for (var i = 0; i < obj.children.length; i++) {
            html += check(obj.children[i],)
        }
        html += '</ul>';
    }
    html += "</div>";
    return html;
}
function assignEvent() {
    $('.ntitle').click(function () {
        var p = $(this);
        var c = p.parent().find('.children:first')
        if (c.hasClass('hide')) {
            c.removeClass('hide');
            p.addClass('open');
        }
        else {
            c.addClass('hide');
            p.removeClass('open');
        }
    })
}

The following is what I currently have which is collapsible if I click on the items: enter image description here

And I am trying to achieve the following: enter image description here

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda