Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript How can I get CSS proerties of element with jquery ?

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #151799
    amis
    Participant

    Hey,

    I want Get CSS properties of element for example

    <p> from style.css

    and then I want set it for another element for example <a></p>

    #151814
    TheDoc
    Moderator

    I generally try to avoid manipulating the CSS directly with jQuery.

    Instead of doing something like this:

    $('.element').css({
        border           : '1px solid red',
        background : 'blue
        // etc
    });
    

    I’d rather to do this:

    $('.element').addClass('something');
    

    And then in your CSS file:

    .something {
        border: 1px solid red;
        background: blue;
        /* etc */
    }
    

    So instead of getting the CSS properties via jQuery, you should probably be figuring out how to utilize classes.

    #151886
    amis
    Participant

    Thx TheDoc for your efforts ,

    I will tell you what i want to do

    I want to replace <header> with <div id="header"> for old browsers and this is ok using replaceWith() jQuery method , then i want get css properties of tagname <header> and set it for new ID #header .

    #151889
    Paulie_D
    Moderator

    That seems like a lot of work when you could just use the HTML5Shiv and you wouldn’t need to replace the header at all.

    Even if you did, you don’t need to copy the properties over…

    header,
    #header {
    your properties here;
    }
    

    A grand total of 8 characters extra.

    #151907
    amis
    Participant

    thx Paulie_D ,
    but i will force every one use my code do this and i don’t want this
    as I want to Create something like HTML5Shiv

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.