jquery: how to determine if a style is set via css class or hardcoded by style attribute? [duplicate]


Tags: jquery,css

Problem :

This question already has an answer here:

For example given two divs like this:

.example{
  width: 200px;
  height: 200px;
  z-index: 4;
}
<div id="first" style="height:100px;width:200px;z-index:5;">Hardcoded</div>
<div id="second" class="example" >Css</div>

How can i detect by jquery/javascript if, for example, the height of the div is set by style attribute? Or how can i detect by jquery/javascript if the height is set but not by a css class?

It seems there is a bunch of misunderstand what i'm really asking, altough one answer was pretty close but deleted: The question is not "which value is set for the height". or "does the div has a specific class set" Given a specific style property like 'height'. I want to know two things:

  1. Is the height set in any non-browser-default way like by a css class or style? (i think i can get by myself)
  2. If yes, is the height set by the style="...." attribute or by a class=""? Which class doesnt matter.


Solution :

You can use jQuery as follows

<script>  
$(document).ready(function() {  
    if($('#first').attr("style").indexOf("height") != -1) {
        alert("height is hardcoded");
     }
    else {
        alert("height is not hardcoded");  
     }

  });
</script>

    CSS Howto..

    Possible to code a search box that searches for a specific tag in a div and then shows it / hides others? [closed]

    how do I make overflowing and float positioned elements stay all on one line?

    CSS how to target 2 attributes?

    How to set the css property of dynamic data

    How to use CSS Loader in my website?

    how to write a css that only can be visible on desktop in bootstrap

    How do I get started with jQuery? [closed]

    Canvas distorts drawing. How do I get the scale factor between the set size and the styled size?

    How do I get these elements to effectively center properly and responsively?

    How do I reference this textarea and checkbox?

    How to create overlaying papers (pile) - CSS / HTML

    How should I create a web interface for my application? [closed]

    How to accomplish this layout with CSS and HTML?

    If div is visible, than show that content in other div with jQuery

    How to do this specifically things in CSS for a table

    How i can change a css of an input[“file”]? [closed]

    How to make elements appear one by one using css animation

    How to make textareas auto-resize using just CSS?

    How do I resize the border of the body as the window resizes in CSS

    How do I conditionally apply CSS styles in AngularJS?

    How can i change background image opacity without changing on div content? [duplicate]

    How to achieve this view?

    How to embed fonts in CSS?

    How to style Accelerator display text in JavaFX ContextMenu via CSS?

    How To Design a Website for the Non-Designer that takes full advantage of JQuery on the client?

    How to make highlighted table with rowspan

    php- How to strip CSS in the text

    How to get css button to stay active after it has been clicked?

    How do I fit a fieldset to the size of its content with CSS?

    How to change text color (and background) on nav bar links when hovering? [duplicate]