Select a badge as a Jquery child element

Asked

Viewed 95 times

0

I got a badge that’s attribute son of a button, that way:

   <button id="equipeum" class="btn btn-primary" type="button"><span id ="pontoum"class="badge"></span></button>

In this case the badge would be a child element of the button (correct me if I’m wrong), anyway, my problem is to be able to change the values of the two, because when the I change the value of the button "equipeum" via JS, the child element badge gets lost.

1 answer

1


Tiago, if you want to insert some content into the element button and the element span, you can do so:

$('button').prepend('Nome');
$('span').text(1);
  • Actually I want to use the 2 elements, Button gets one value and Span who is his son gets another. Draw?

  • 1

    @Thiagosilveira, by value you mean the content of the element?

  • This @leoklaj, the button gets a name and the badge gets a numbering, only when I grab the button by the id, it ends up filling everything and I can’t change the contents of the badge.

  • 1

    $('button'). prepend('name here') and $('span'). text(1)

  • 1

    Perfect @leoklaj, edit the answer so I can take it for granted.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.