Below I have an image button:
<table id="question">
<tr>
<td colspan="2">
<a onclick="return plusbutton();">
<img src="Images/plussign.jpg" width="30" height="30" alt="Look Up Previous Question" class="plusimage" id="mainPlusbutton" name="plusbuttonrow"/>
</a>
<span id="plussignmsg">(Click Plus Sign to look up Previous Questions)</span>
</td>
</tr>
</table>
Now what I want to do is by using jquery I want to hide the current image Images/plussign.jpg and replace with another image Images/plussigndisabled.jpg in the if statement below:
if (qnum == <?php echo (int)$_SESSION['textQuestion']; ?>) {
}
And then in the document ready function I want it to replace the Images/plussigndisabled.jpg with Images/plussign.jpg
I want to know what is the best way to achieve this in jquery?
UPDATE:
Below is what I tried:
var x = "<img src='Images/plussigndisabled.jpg' width='30' height='30' alt='Look Up Previous Question' class='plusimage' name='plusbuttonrow'/><span id='plussignmsg'>(Click Plus Sign to look <br/> up Previous Questions)</span>" ;
if (qnum == <?php echo (int)$_SESSION['textQuestion']; ?>) {
$('#plus th').html($(x));
$("#showGridId").unbind('click').click(function (event) {
event.preventDefault();
return false;
}).css('color', '#BBBBBB');
}
Thanks
Do it all in PHP :
Then output the image like so :
You cannot access PHP variables in JavaScript and you cannot access JavaScript variables in PHP … and I don’t see the point of casting if you stored the variable in the session in the first instance !
Update
Not really sure why you are doing this … but try something like :