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

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');. Commented Feb 18, 2015 at 15:26
  • seems that it is inside an <iframe>, check this link out: changing elements from iframes jquery Commented Feb 18, 2015 at 15:30
  • dont work for me, can you see the image in attachment there is more code of that page... Commented Feb 18, 2015 at 15:30
  • Santiago, yes it is in an iframe i will try something from your link Commented Feb 18, 2015 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... Commented Feb 18, 2015 at 15:48

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

dont work, maybe i need to include id of iframe... because class is in iframe
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. :(
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.

5 Comments

@boshermen Try now . I was in other domain ! :)
this will not refer to the div you want in this context
@devqon , Updated to target proper div
No you didn't. The this does not points to the context where the if() applies on
@SantiagoHernández , multitasking on multiple question makes me crazy . Edited.
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/

4 Comments

i dont have id in DIV (its generated page by embed code)... Can you see image in attachment
@SantiagoHernández I know... He wants to remove the class. So if it's always true. It will always remove the class.
@SantiagoHernández It's called a sanity check. I don't want to run the code if there isn't any div with the role='toolbar' on screen anymore.
@SantiagoHernández Should be fixed.
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')

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.