Remove class from a div with a specific ID

Asked

Viewed 94 times

0

You can remove a class from a div with a ID specific?

That one div is dynamically inserted through the append, and each receives its own ID. Only there are times I need to remove only ONE div which was inserted with append, as they have the same class but not the same ID, has something to do with?

For example:

$('.remove > id = 6').remove();

it is possible?

  • 1

    $("#6").remove() does not resolve? How do you want to remove? By clicking a button?

  • $("[id='6']").remove() I was just about to write this... I didn’t quite understand another option

  • No... I’m gonna dynamically remove, along with the append.

  • I get the id like this: Results.rows.item(i). id; how could I remove it like this? $(Results.rows.item(i).id). remove()?

  • Not knowing what it is results.rows there’s no helping you.

  • It is the result of my query in the database. Results.rows.item(i). id returns me id. So, I store it in a variable. var id = Results.rows.item(i). id;

  • Since you have the identifier saved in a variable, consider the # with the handle and have it removed, try so: $('#' + id).remove();

  • @Pebble with the remove class would look something like this? $('.remove> #' + id). remove();

  • 1

    It would be yes, but as @fernandosavio commented, there is no need to specify the class, because the identifier is unique (at least it should be) and already works to find the element.

  • He wants to remove only the id that contains the remove class, so he will have to do a each in the remove class and remove the ids inside the loop

Show 5 more comments

1 answer

0

Concatene the class the id in the selector:

$('.remove#6').remove();

Which means you should remove every element that has the "remove" class and the id "6";

Remembering that the id should be unique among all elements of your page, so you could use only:

 $('#6').remove();

https://www.w3schools.com/jquery/jquery_ref_selectors.asp

  • In javascript to remove a class from an element in ID var demo = document.getElementById("demo");
demo.classList.remove("classe-para-remover"); if you also want to add and remove the class for an event you can use toggle demo.classList.toggle("class-manipulada");

Browser other questions tagged

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