how to get css of a clicked div using jquery?


Tags: javascript,jquery,css

Problem :

Can anybody know how to get border-color of a div using jquery.

Jquery:

$("#divcolor").click(function (){
  alert("dsf");
  var divcolor = $(this).css("border-color");
  alert(divcolor);
});

Html:

<div id="divcolor" style="border:#333333 solid 1px;" >
This is the target
</div>

In divcolor variable i am not getting anything.



Solution :

Using the CSS jQuery function like you did:

http://docs.jquery.com/CSS/css#name

But read this paragraph:

Shorthand CSS properties (e.g. margin, background, border) are not supported. For example, if you want to retrieve the rendered margin, use: $(elem).css('marginTop') and $(elem).css('marginRight'), and so on.


    CSS Howto..

    How to display icon with text in html with the help of css?

    Jquery Hashtag link system (show what page the user is on)

    If a child has a certain specific value, how to check and make “true” so that hover of the parent yields a result?

    CSS selector for showing descendants doesn't work properly

    How to remove a css class using jquery in a certain screen size

    How can i dynamically change title of input type file?

    How to wrap or label all divs like files in opertaing systems (jQuery) [closed]

    How to repeat a menu without using iFrames or PHP in simple HTML/CSS or XML?

    How to force a div to scale at 100% width of the current windows Browser

    Jquery: How to check if the element has certain css class/style

    How to show sorting order if column width is smaller than caption in free jqgrid

    How to change css image via php depending on weekday

    How to apply css on every 2nd child using nth-child() with jquery

    How to stop Navigation bar list from changing position?

    How do I make a div expand to the width of the page with css?

    How to get CSS of element (% vs px)

    Css selector : How to reference a attribute inside a div

    How to collapse div same like facebook chat

    Javascript slideshow that gradually zooms on image [closed]

    Trying to align text with background image. If below a certain resolution the text to the left moves in. How can I fix this?

    How can I change this HAML format to normal CSS style?

    how to write set of styles as a function in compass sass

    How to change text direction of every line of text using javascript/jquery?

    How to make a barlike chart but only with html and css [closed]

    Flexbox and Bootstrap How to Put Image in Navbar Brand Area

    How do I vertically align the text to the middle using CSS?

    How to remove the BG image on jQueryUI autocomplete combo (select)

    How to style a form action [closed]

    how to use jquery to add css based on screen width

    How to add CSS class dynamically to html element