How style DIV when the id inclue strings in php?


Tags: php,jquery,css,jquery-click-event

Problem :

How to use CSS or jQuery to style my background-color in DIV when the id inclue strings in php?

My code is:

<div id='result_'.$item_id.'>item</div>


Solution :

You can attach a class to your div and use a jquery selector to get your div(by id or class) and change its css properties using .css(). Also I think you want to change the background after clicking on a specific div, so you need to attach also a click handler, extract its id and then change its background color.

<div class="my_class" id='result_'.$item_id.'>item</div>


   $(".my_class").click(function(event){
        var clicked_id_item = $(event.target).attr("id").split("_").pop();
        $("#result_"+clicked_id_item).css('background-color','black')   
    })

    CSS Howto..

    How can I make images stack on top of each other as web page scales down?

    how to get double border in using CSS?

    How does one change the colour of a div based on current time?

    How to alter css style from parent page inside an iframe using jquery

    How to uniformly darken colors?

    How to make hover css menu fade in and out?

    How do you create a html scrollable area, that just uses the main browser scrollbar

    How to set CSS attributes relative to a parent node?

    howto hide outline on a form

    In javascript, how to get a class name from a td cell?

    How to style the values in a textfield using CSS?

    How to have a different visited link colour in 2 sections of a html?

    How to select all elements that are not of a class within an id css

    How to add sub-menu (css) under actual sub-menu in WordPress

    colspan doesn't accept decimal numbers. How do I specify the span?

    CSS3 - How to “restore” ::-webkit-scrollbar property to the default scroll bar

    How do you associate a css/sass stylesheet to a view in rails?

    HTML/CSS: how to put all
  • in
      on the same line and centered [duplicate]
  • CSS - how to display submenu options horizontally while maintaining spacing of horizontal main menu options

    How to add a color transitions in CSS and HTML like the one in the login area of the Instagram app?

    How to mix 100% height with a minimum height

    HTML 5 / CSS (??) how to cause a div element to be on the next line?

    How to inscribe the following shape with CSS inside div?

    How to iqnore mousemove event on child ul

    how would I use Javascript, html and css to produce the running tiger effect seen in run4tigers website? [closed]

    How to center align ion icon inside button?

    how to change a css of an input if the value of it is not empty in angularJS

    How to apply CSS3 rendering for optimal performance

    how to route to css/js files in mvc.net

    How to shrink the menu when mouse hover on a link using jquery