Currently I am trying to compare two variables, newhtml and oldhtml.
I get the old html using:
var oldhtml = $('#pop').html();
I get the new html using:
var newhtml = ("<%= escape_javascript render(:file => 'shared/_content') %>");
I’m then trying to compare them using:
if(newhtml == oldhtml)
{
//is never called
$('#pop').hide();
}
else
{
//is always called
$('#pop').html(newhtml);
}
but it’s not working. In this scenario the oldhtml variable is actually just the previous newhtml variable. So, if you click on the same content on the main page newhtml should actually just be a ruby on rails generated version of oldhtml (the html present in <div id="pop">). I’ve tried appending them to see where there difference lies, but it looks exactly the same to me. I was hoping someone could nudge me in the right direction? Thanks!
That was all very helpful and I actually sort of combined the answers to get something that worked. What ended up working is this:
Get the oldhtml like before:
Then insert the new html into the div:
Following that, get the newhtml from the div, the same way I retrieved the oldhtml:
The if statement then works, but you want to make sure to change the div to something arbitrary that can’t be retrieved from your database: