I’m pretty confused by this. My jQuery code works when it is on the .erb page, but not when in my rails app instanokia.js file. Can anybody explain why this is not working? I have a an alert that works and pops up on .ready so jQuery is loading fine…
On my .erb page: (works)
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<div id="experiment" value="toggle">
<p>Hello</p>
</div>
<input type="button" id="toggleButton" value="toggle" class="btn btn-primary exp" />
</div>
</div>
<script>
$('#toggleButton').click(function() {
if ($('#experiment').is(':visible')) {
$('#experiment').hide();
} else {
$('#experiment').show();
}
})
</script>
In my instanokia.js file: (does not work)
$(document).ready (
alert('working!')
)
$('#toggleButton').click(function() {
if ($('#experiment').is(':visible')) {
$('#experiment').hide();
} else {
$('#experiment').show();
}
})
It needs to be