Insert a label to all the labels that have a class in specific

2

I want to insert a li tag into all ul that have the class or id 'father' . And that ends something like this:

<ul id='padre'>
  <li id='hijo'></li>
  <li id='hijo'></li>
</ul>

<ul id='padre'>
  <li id='hijo'></li>
  <li id='hijo'></li>
  <li id='hijo'></li>
</ul>

<ul id='padre'>
  <li id='hijo'></li>
  <li id='hijo'></li>
  <li id='hijo'></li>
</ul>

The code I'm using is this

$(document).ready(function () {
  $('#padre').after('<li>NIVEL 3</li>');
});

But just add that li to the first ul that has the id 'parent'

    
asked by JiMel 31.10.2018 в 17:00
source

1 answer

3

Use JQuery, it's simple using the append , you can use a class padre to work in all:

	
$(".padre").append("<li>Test hijo</li>");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class='padre'>
  <li id='hijo'>1</li>
  <li id='hijo'>1</li>
</ul>

<ul class='padre'>
  <li id='hijo'>1</li>
  <li id='hijo'>1</li>
  <li id='hijo'>1</li>
</ul>

<ul class='padre'>
  <li id='hijo'>1</li>
  <li id='hijo'>1</li>
  <li id='hijo'>1</li>
</ul>

The function of append consists of inserting the specified content at the end of each element in the set of matching elements (in this case those containing the class class='padre' ).

You can access the following route: link , it explains more in detail what the append consists of. I hope it helps you.

    
answered by 31.10.2018 / 17:04
source