1

I want to remove class "ndfHFb-c4YZDc-aSZUA-Wrql6b" from div (to hide some toolbar)See image

<div class="ndfHFb-c4YZDc-aSZUA-Wrql6b" role="toolbar" style="width: 226px; right: 12px; opacity: 1;"><div class="ndfHFb-c4YZDc-aSZUA-Wrql6b-AeOLfc-b0t70b"><div class="ndfHFb-c4YZDc-nJjxad-nK2kY......

i try to do it simple with

$('.ndfHFb-c4YZDc-aSZUA-Wrql6b').remove();
$('div.ndfHFb-c4YZDc-aSZUA-Wrql6b').remove();

but it dont work. Thanks in advance

mire_ba
  • 74
  • 6
  • 2
    The `remove` method will remove the element from the DOM. If you want to remove class, you have to call `removeClass`. For example: `$('.ndfHFb-c4YZDc-aSZUA-Wrql6b').removeClass('ndfHFb-c4YZDc-aSZUA-Wrql6b');`. – haim770 Feb 18 '15 at 15:26
  • seems that it is inside an ` – Santiago Hernández Feb 18 '15 at 15:30
  • dont work for me, can you see the image in attachment there is more code of that page... – mire_ba Feb 18 '15 at 15:30
  • Santiago, yes it is in an iframe i will try something from your link – mire_ba Feb 18 '15 at 15:46
  • IMHO, if you're using the presence of the class to flag its visibility, and that class is the only thing distinguishing that element from any other, then you're doing it wrong, since you just destroyed the very thing that'll let you reinstate the element later... – Alnitak Feb 18 '15 at 15:48
  • Hi, did you get it to work? I cannot hide the toolbar.. –  Apr 19 '16 at 16:20

4 Answers4

1

You were really close.

$('div.ndfHFb-c4YZDc-aSZUA-Wrql6b').removeClass('ndfHFb-c4YZDc-aSZUA-Wrql6b');

is the correct solution. Make sure not to include the class' . when using removeClass.

I'd encourage you to rename the class to something more human readable.

Also, as Donte suggested, it would be best if you gave the div an id to allow you to target it consistently.

Joshua Plicque
  • 418
  • 7
  • 10
  • dont work, maybe i need to include id of iframe... because class is in iframe – mire_ba Feb 19 '15 at 09:15
  • You can't apply any CSS or JS to stuff in an iframe. An iframe is essentially an embed of a completely different site. You can't mess with it's HTML structure. :( – Joshua Plicque Feb 19 '15 at 15:45
0

Personally I would set an id to the div and then target the id in jquery... Then remove the Class.

if($("div[role='toolbar']").length){
  $("div[role='toolbar']").removeClass('ndfHFb-c4YZDc-aSZUA-Wrql6b');
}

Link: http://jsfiddle.net/g0srar72/2/

dowomenfart
  • 2,803
  • 2
  • 15
  • 17
0

To remove class use removeClass

EDITED

if($('div[role="toolbar"]').hasClass("ndfHFb-c4YZDc-aSZUA-Wrql6b")){
    $('div[role="toolbar"]').removeClass("ndfHFb-c4YZDc-aSZUA-Wrql6b");
}

Refer Link

Explanation : Grab Div with role toolbar and check if it has class XYZ if yes remove the class from that div.

Pratik Joshi
  • 11,485
  • 7
  • 41
  • 73
0

So as I've understood the problem comme from the fact that it is included in a <iframe>

In this case you can try something like :

$('iframe').contents().find('[role="toolbar"]).removeClass('ndfHFb-c4YZDc-Wrql6b')

Baldráni
  • 5,332
  • 7
  • 51
  • 79