First, thank you all for your answers!!!
I removed the typo and did what you told me! The firebug console is
finding the $(".show1") and it is hiding the row if I type $
(".show1") .hide()
So I tried your example with the log output, but Firebug says me "$
(document).ready is not a function"
My application.js is looking like this:
$(document).ready(
function(){
$("#filters input:checkbox").click(function(){
console.log("hey there");
});
}
);
I found another example on the jquery api documentation. If I put this
into my application.js then it is printing the text:
$(document).ready(function () {
$("p").text("The DOM is now loaded and can be manipulated.");
});
That is pretty strange...!
Has anyone an idea?
On 24 Okt., 20:06, radhames brito <[email protected]> wrote:
> On Mon, Oct 24, 2011 at 10:56 AM, Walter Lee Davis <[email protected]>wrote:
>
>
>
>
>
>
>
>
>
>
>
> > On Oct 24, 2011, at 10:50 AM, Roy Situmorang wrote:
>
> > > I'm sorry for the typo, I have just fixed the code as follow:
>
> > > (function() {
> > > $("#filters input:checkbox").click(
> > > function(){
> > > class_to_show = $(this).attr("id");
> > > switch(class_to_show){
> > > case 'show1':
> > > $(".show1").show();
> > > $(".show2").hide();
> > > break;
> > > case 'show2':
> > > $(".show1").hide();
> > > $(".show2").show();
> > > break;
> > > default:
> > > $(".show1").show();
> > > $(".show2").show();
> > > }
> > > })});
>
> oh , ok im back.
>
> Well first lest see what is wrong. if you have chrome or firefox right -clk
> on the page and lick inspect element, that should bring the inspector up.
> then enable the console if is not enabled.
>
> type
>
> $(".show1")
>
> the console show show all the elements that match the selector if it does
> not you are not importing the js library. if it does then type
>
> $(".show1") .hide()
>
> see if the row disappear. if they they do then will have to deal with the
> event attachment seems it does not seem to be working.
>
> go to the application.js and type
>
> $(document).ready( <== this is importan so that jquery
> first waits for the rows to actually exists
> function(){ <== inside this function goes the
> code
>
> $("#filters input:checkbox").click(function(){
> console.log("hey there ");
> });
> }
> );
>
> this should make a hey there appear in the browser console everytime you
> click a checkbox, dont forget to reload the page everytime you change the
> application.js file.
>
> Im almost sure that you are missing the $(document).ready(); event , is very
> important because if the js loads before the checkboxes are rendered no
> event will be attached to them. $(document).ready(); causes the javascript
> to wait untill the entire page has loaded before doing anything.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.