I have a web page with HTML as below:
<head>
<script type="text/javascript" src="jquery-1.5.1.js"></script>
<style type="text/css">
#content{
width: 200px;
height: 200px;
background-image: url(images/loader.gif);
background-position: center;
background-repeat: no-repeat;
border: #3399FF solid 2px;
}
</style>
</head>
<body>
<div id="content">stringname</div>
</body>
I have set a loader GIF as its default background. I have a PHP file, ajax.php which return a number (or name) with respect to a $_POST["filename"]. What I want is, the page send text inside the div (here stringname) and the AJAX will return a name or number. When the script get this data, the background URL may be changed to return_data.jpg (where this return_data is a name or number).
I think the background change script is something like:
var $cell = $('#content');
$cell.css('background-image', 'url(images/loader.gif)')
How can I do this jQuery?
and don’t forget adding the jQuery script tag to the bottom of your -body- tag (but still inside it):