0

I have 6 specific pages with plenty of following html line:

<div class="ms-webpart-chrome ms-webpart-chrome-vertical ms-webpart-chrome-fullWidth ">

I need to remove the first css element that is "ms-webpart-chrome" with jquery on all of these specific pages.

What "ms-webpart-chrome" does is that it adds a white background that I would like to remove from all of the pages.

How can I do that?

4
  • Have you Googled jquery remove element? It gives me this as the first result: api.jquery.com/remove Commented Feb 25, 2013 at 13:18
  • 2
    Do you mean you want to remove that class name from the elements, or remove the actual elements? Commented Feb 25, 2013 at 13:18
  • I want to remove the class ms-web-chrome from the div tags, which will remove the white background automaticly if the class is removed Commented Feb 25, 2013 at 13:48
  • maby removing it from the css with jquery is easier way to deal with this? Commented Feb 25, 2013 at 13:48

3 Answers 3

1

This is a fairly straightforward use of jQuery. First, you look up elements with that class using a class selector, then you use first to ignore all of them except the first one, then you do something with that element.

What you actually want to do is a bit unclear from the question, but there are two likely options:

If you want to actually remove the element, use remove:

$(".ms-webpart-chrome").first().remove();

If you just want to remove that class from it, use removeClass:

$(".ms-webpart-chrome").first().removeClass("ms-webpart-chrome");

Using .first() is the most efficient option in my experience, but it's unlikely to matter. The first bit (looking it up by class and getting just the first one) can also be done using the :first selector (or :eq(0)):

$(".ms-webpart-chrome:first").doSomething();

In both cases, that may force jQuery to use its own selector engine rather than built-in browser features, which may not be ideal. But if you're only doing this once, it would only matter on a truly massive page.

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

1 Comment

$(".ms-webpart-chrome:first").removeClass("ms-webpart-chrome"); also should do
0

If each page has a class .pages you can use each to loop through each page and remove the first element with the class ms-webpart-chrome

$('.pages').each(function(){
$(this).find('.ms-webpart-chrome:first').remove();
});

Comments

0

By using jQuery :

$(function(){
$('.ms-webpart-chrome').each(function(){
$(this).removeClass('ms-webpart-chrome');
})
})

By using CSS :

Find the CSS file and search for '.ms-webpart-chrome' and delete the whole line.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.