1

In my css i have

    * {
 font-family: "Meiryo UI" , Verdana;
 font-size:13px;
 }
input, select, textarea {
 font-size: 12px;
 border-color: #333;
 color: #333;
 border-style: solid;
 border-width: 1px;
}

But, i want one DIV without CSS. I tried

$('#preview').removeClass()
$('#preview').removeAttr("style")
$('#preview').children().removeAttr/Class

But...but without result. Help me to remove all style from this div with Jquery or just some javascript.

He come from stylesheet. This is preview pic for my question: https://emailinvest.com/preview.jpg what i want.

3
  • is that CSS coming from stylesheet or is it inline? Commented Jul 18, 2010 at 7:14
  • you nned to show your html becuase i dont understant what is the connection between your css for textarea and your need for a "div without css" Commented Jul 18, 2010 at 8:55
  • HTML is simple. Just <body><div id="preview">Text without CSS</div></body>. Because selector * in css, my #preview have font-family: "Meiryo UI" , Verdana; font-size:13px; I need Javascript to remove all style from this DIV no matter any css declarations. Commented May 14, 2015 at 11:07

3 Answers 3

3

Inheritance in CSS is more often helpful than not helpful, therefore take another route by either:

a) Override the styles you specified

#preview .input, #preview select, #preview textarea { }

or

b) Make the styles you specified target a different area using a prefixed selector, eg

#selector * { font: 13px "Meiryo UI", Verdana; }
#selector input, #selector select, #selector textarea { }
Sign up to request clarification or add additional context in comments.

1 Comment

You need to be FAR more specific. I was giving general advice.
0

If you want to use removeClass you must specify what class to remove or it won't work:

$('#preview input').removeClass('classToRemove')

$('#preview button').removeClass('classToRemove')

You can check with Firebug what class is given to that button and try to remove it like that.

Or you can set your styles directly to that:

$('#preview button').css('background','#ccc');

Or this one.. but I'm not sure it works:

$('#preview').children().removeAttr('class'); // or 'style'

1 Comment

There is no classes on my div. Just global declarations from all css files.
0

Your stylesheet does not specify classes or specific elements (IDs) and therefore the styles are being applied to all elements which match by tag.

Specifically, your button is being styled by the "input" element style specified in the stylesheet.

This means you do not have any classes you can easily remove to reset the style.

Buttons in particular are very difficult to set back to their original style once they have been set to something different, particularly in a cross-browser-friendly way.

You have a few options, of which only one is sensible:

  1. As meder has suggested above don't set the style for this div in the first place. This is the best option. You can do this by either setting explicit class names or ids for your other divs and listing them in the stylesheet, OR add a class for the div you want to ignore, and use the "not" selector, eg input:not(.myUnstyledButtonClass) (this only works in modern browsers)
  2. Manually construct your DIV inside an IFrame so it is not subject to the main document's styling. This seems like overkill though
  3. I haven't tested this one, but you could try creating an iFrame, rendering a button (which would be of the unstyled form) and then iterate and recurse through and copy all properties and styles of the unstyled button to the button in your div. There's a very slim possibility this would work. I wouldn't even bother trying it however....

Go with 1 - what meder has suggested. It's probably worth posting up the code you have tried using when you commented to him that "I tried...no result". Chances are you've simply misinterpreted his suggestion or overlooked something.

For an example, see: http://jsbin.com/ikobe4

To use ":not()" you need to add unstyled (or whatever you choose) as a class on your button, eg:

<input type="button" class="unstyled" value="Button Text" />

And change the selector in the css file from

input, select, textarea {

to

input:not(.unstyled), select, textarea {

...but as mentioned, this wont work in all browsers, so your best bet is to add classes to all the other divs, and explicitly specify which divs you want to apply styles to, rather than specifying which you don't want to apply styles to

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.