Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

jquery .css() .attr() i tried every thing

jquery .css() .attr() i tried every thing

Problem

#centerdiv {
    position:fixed;
    top: 40%;
    left: 50%;
    width:30em;
    height:18em;
    margin-top: -9em; 
    margin-left: -15em;
    border: 1px solid #ccc;
    background-color: #f3f3f3;
    -moz-border-radius: 15px;
    border-radius: 15px;
}

#errorcenterdiv {
    position:fixed;
    top: 40%;
    left: 50%;
    width:30em;
    height:18em;
    margin-top: -9em;
    margin-left: -15em;
    border: 1px solid #ccc;
    background-color: #f3f3f3;
    -moz-border-radius: 15px;
    border-radius: 15px;
}

Can some one tell me WHY i can't get this work on jquery i don't know i start believe that there is something wrong with the css code that i don't recognize .

Problem courtesy of: undefined

Solution

if you are trying to add styles dynamically, use IDs to reference but classes to add the style. using IDs to append styles can have unexpected consequences (no styles applied)

so if you want a centered div

stuffing

just reference via ID (centerMe), and add a class (centerDiv):

$('#centerMe').attr('class','centerDiv');

or

$('#centerMe').addClass('centerDiv');

your css rule should have the "dot" (.) instead of "hash" (#)

.centerdiv {
    position:fixed;
    top: 40%;
    left: 50%;
    width:30em;
    height:18em;
    margin-top: -9em; 
    margin-left: -15em;
    border: 1px solid #ccc;
    background-color: #f3f3f3;
    -moz-border-radius: 15px;
    border-radius: 15px;
}
Solution courtesy of: Joseph

Discussion

View additional discussion.



This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

jquery .css() .attr() i tried every thing

×

Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription

×