Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using :before via Jquery

Tags:

jquery

I have the current issue: I define via CSS the current role for a div element

.divElement:before {
    background-image: url(../images/triangle.png);
    background-repeat: no-repeat;
    content: "";
    height: 20px;
    left: 62%;
    margin: 0 0 0 -50px;
    position: absolute;
    top: -20px;
    width: 100px;
}

.divElement{
    background: none repeat scroll 0 0 #FFF8D6;
    border-radius: 10px 10px 10px 10px;
    color: black;
    font: 1em/1.4 Cambria,Georgia,sans-serif;
    margin: 0px 500px 3em;    
    padding: 15px;
    position: relative;
    text-align: center;
}

I created this element dynamically using jQuery: $('<div class="divElement"><p><strong></strong></p></div>').appendTo(....) this works correctly. The issue becomes when using jQuery and I try to dynamically change the backgroung-image and the top attribute of the content before the divElement (which I define in CSS with :before)

I tried something like this for the background-image, but doesn't work:

$('.divElement:before').css('background-image', 'url(../images/triangle_reverse.png)');

How can I do that? Thank to all !!!

like image 404
user1645419 Avatar asked Apr 01 '26 12:04

user1645419


1 Answers

The following will search for all nodes with class .divElement, take the corresponding elements that appear before tem and change their background images. Is that what you're trying to accomplish?

$('.divElement').prev().css('background-image', 'url(../images/triangle_reverse.png)');
like image 158
Remo Avatar answered Apr 03 '26 05:04

Remo