0

Have you noticed that every 10 questions on this site is about jQuery?

Anyway...

I'm using jQuery for the first time. I don't know if I loaded it correctly. When I run this code:

                 <script type="text/javascript">
                     function allDayClicked() {

                         if (jQuery) alert("loaded");

                         var allday = document.getElementById("allDayEvent");
                         var start = document.getElementById("<%=startTimeSelector.ClientID%>");
                         $('allDayEvent').hide();
                     }
                </script>

The alert appears, saying "loaded", but nothing else happens; the html checkbox doesn't go invisible. I get no kind of error in my javascript output.

Is it possible I haven't successfully loaded jQuery? I added a reference to it in my visual studio project and generated this by dragging it to default.aspx:

<script src="Scripts/jquery-1.6.1.min.js" type="text/javascript"></script>

Otherwise, what's going on?

1
  • jQuery Documentation is very good and the examples is very clear, you should take a look. Commented Jun 10, 2011 at 3:56

4 Answers 4

5

jQuery takes a css selector, not an id. If you want an id use the css form of declaring an id.

$('#allDayEvent').hide();
Sign up to request clarification or add additional context in comments.

Comments

4

jQuery is loaded fine, you're just using it incorrectly. You should be doing either:

$('#allDayEvent') // recommended, the '#' means ID

Or:

$(allday) // since you already grabbed it with getElementById

jQuery can take a lot of different objects with $(). The options are listed here.

1 Comment

that's awesome... jQuery is amazing.
3

You are missing the # in your ID selector.

Change $('allDayEvent').hide();

to

$('#allDayEvent').hide();

Comments

1

Assuming that your checkbox has an id "allDayEvent", you just need the hash (#) in this line:

$('#allDayEvent').hide();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.