The php and html are pretty simple:
<?php
session_start();
$_SESSION['liked_or_not']=0;
?>
<button class="photo_like" value="<?php if($_SESSION['liked_or_not']==0){ echo 'Like';} else{ echo 'Unlike';} ?>" ><?php if($_SESSION['liked_or_not']==0){ echo 'Like';} else{ echo 'Unlike';} ?>
jQuery snippet:
<script type="text/javascript">
$(document).ready(function(){
alert("alert one ="+ $('.photo_like').text());
if($('.photo_like').text()=='Like'){
alert("alert two ="+ like_text);
}
});
</script>
The above code gives the ouput as ‘alert one =Like’ and then after a few invisible line breaks on the alert box a square. How does that square appear there?
And the second alert box does not appear, as the square box is not included in the if($('.photo_like').text()=='Like'){ comparison.
Also Chrome console says :Uncaught TypeError: Cannot read property ‘hasPort’ of undefined
Explanation?
You should close your button.
And use ternary operator can make your code more clear.