Rich-text Reply

Remove multiple elements

VimVic 02-02-16

Remove multiple elements

Hello,

please can you tell me best practice for removing same element on webpage? On my website https://www.vimvic.cz/kurzy I want to remove bold: 

<a href="/kurz/jak-na-paleo-dietu" class="course-type online">
<strong>Online kurz</strong>
</a>

What is the best solution?

Level 1

JDahlinANF 02-02-16
 

Re: Remove multiple elements

Removing all of that changes the alignment of the images on the page... doesn't look like that is exactly what you want to do, but, to answer your question...

 

Since your anchors will be empty, there is no need to keep them in the DOM at all, so you can just detach them.

Each of these anchors is identified by the combination of classes on the anchor tag "course-type online"

To remove them, use either of these as your variation's code:

$('.course-type.online').detach();

or

$('.course-type.online').remove();

 

Joel_Balmer 02-02-16
 

Re: Remove multiple elements

Hi @VimVic!

 

To 'un-bold' some text that is already bolded, one simple solution is to change the html of that element to not include the <strong></strong> tags. Using <a></a> tag and classes you've supplied, you can select those elements that match that, with variation code like so:

 

$('a.course-type.online').html('Online kurz');

 

I hope that helps!

JDahlinANF 02-02-16
 

Re: Remove multiple elements

However, if you want to keep the alignment of your images on the grid, rather than removing them like I showed in the previous post, you may want to only remove the class that gives it the green background and remove the text inside of the anchor, like this:

$.each($('.course-type.online'), function(){
  $(this).removeClass('online').html('');
})

This code says:

"For each 'course-type.online', remove the class 'online' and set the html inside of it to blank"