September 18, 2012

How do i change an element on Database update

Question by Varun Dhamija

Here’s an example of what i am doing :- i am populating the div with mysql database through php and there are two divs , clicking on Button (chat) hides the div 2nd div and clicking on (chat2) hides the first div and shows the second (using jquery)
(Both the divs are showing data of different tables )

Now what i want is when div1 is hidden and the database/table (that the hidden div is showing) is updated i want to change the css property of button(chat). I know that it can be done via Ajax but i am not very good at it , So please help me out.

and i am populating the div via Ajax .

enter image description here

Answer by Starx

I don’t think changing the CSS property has anything to do with AJAX. First you have make the AJAX request and when the request completes then you can do the update and change the CSS at the same time.

For example:

$.post("urltopost.php", { vartosend: 'value to send' }, function(data) {
    console.log(data); //Retrieve the data
    $("#div1").html(data); //Update the data

    //Change the css of the button now
    $("#div1button").css({ color: 'red' });
});

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!