Quiz
- the difference between $(" ") and $("# ")
The selector language in jQuery is exactly what it is in CSS. In CSS:
So, in jQuery, it's just the same:
- I guess the definition of DOM and question 2 of finding the element with the ID
We find elements by using the CSS language in the jQuery function:
- Could we go through the different functions in jQuery such as find and learn how they are implemented. I had such a hard time knowing how to use find in the quiz.
.find()
wasn't in the reading and it wasn't a correct answer on the quiz.(There *is* a jQuery
.find()
method; which we'll get to later in the course. - What would make a wrapped set empty? A spelling error?
Yes. So:
$(".improtant")
versus$(".important")
.Or maybe there just don't happen to be any
.important
elements on the page. So it might not be an error, which is why jQuery doesn't complain.However, for beginners, it's *usually* an error.
- How does the attr modifier differ from css?
Attributes are things like
src
,href
,class
,id
and such.CSS can be modified with the
style
attribute, which is what the jQuery.css()
does. - Can we go over in class why this is true:
$("h3events").click(turnEventsRandomColor); // works $("h3events").click(turnEventsRandomColor()); // fails"
Yes; this is very important.
The first hands a function to the
click
method. The second *runs* the function and hands the return value to theclick
. That's *very* different. - I'm a little confused with the click method. Can you re-explain this in class?
Sure. The
click
method takes the function that it is passed and persuades the browser to call/execute/invoke that function whenever the user clicks on any element in the set. So: - Can we go over question 4 in this quiz? To my knowledge selecting paragraph elements should be $("p"). So what does that expression do?
You're right; that's how you select a paragraph element:
$("p").css('color','green');
would change all the paragraphs to green text.Unfortunately, the information in the reading that went with that question got lost, so the question should have been omitted. I'm sorry for the error. I'll remove the question from the Sakai quiz.
If you're curious: we can use jQuery to create new elements, rather like
.append()
. That's what's happening with$("<p>")
- the difference between keypress/keydown/keyup
A key going down is different from a key going up, particularly if you're going to hold a key down while you, say, move the mouse.
The keypress event is now deprecated; don't use it. But it was just an example anyhow.
- What is Ajax? How is it related to jQuery?
Ajax is a way that JavaScript can interact with a server. We'll get to Ajax much later in the course. jQuery used to make Ajax way easier than in raw JS, but then they changed Ajax in raw JS, so it's not as big a difference.
- I don't really have any question! Thanks!
Great!