This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by Samantha
over 8 years

Understanding the Syntax in JQuery

I’m still trying to wrap my brain around why when we are accessing elements in the jquery functions like “$(“p”); … why we have to put the elements or css attributes in “”. I guess it just seems odd that an actual html element has to be written as a string when accessed by javascript. But I guess if we didn’t put it in parentheses - when the script is ran it would assume that we were referring to an actual javascript variable.

So when we write these as strings in the jquery functions [ ex: css(“background-color”, “dkfjdkfj”); ] does the browser look at the JS and say “ok, I’m going to look at the DOM and search for this literal string of characters and then act on it - does it already know that we’re really referring to an actual node/object in the DOM and adding the “” basically lets it know we’re not referring to a JS variable?

Answer 5606feac9113cb3d3100040e

0 votes

Permalink

jQuery selectors are synonymous with CSS selectors, but as you have observed in jQuery we need to quote the selector so it is not treated as a JS identifier (variable name). The selectors are treated exactly the same as CSS once they are parsed out of the code by the compiler.

points
Submitted by Roy
over 8 years

Answer 560a0b0b86f552e58d000336

0 votes

Permalink

Seeing Samantha’s post expressing the same bewilderment I’ve been experiencing, recalling the great learning experience I’ve had with other codeac courses, and talking with some jQuery-knowledgeable people I happen to know, all confirms me in the opinion that this course is badly in need of a redo. The course author needs to imagine what it’s like to now already know this stuff, and not be so elliptical and stingy with explanation.

points
Submitted by royfischer
over 8 years

1 comments

Roy over 8 years

Warts and all, this is not a course but an introduction that only scratches the surface. The author has been gone for over two years and will not be returning. Codecademy learning tracks are little more than an outline and the onus is on the learner to fulfill their end of the bargain with follow-up and continued study. With no real syllabus in place, how can we fault any of the course authors who gave freely of their time and energy in creating these tracks. The most successful learners here are never the ones complaining, only the fledglings who come in thinking they are going to find a job after taking these tracks. News flash… Ain’t gonna happen. For that to happen, two to four more years of intensive study await.

Answer 560d85663e0ec81d7f000185

0 votes

Permalink

I would like to apologize for the tone of what I wrote. Frustration got the better of me.

I was not aware, if I’m understanding what you seem to imply, that course authors are volunteers. That does change one’s perspective.

And I could not agree more about the realities of what can and can’t be done in a given amount of time; ironically my frustration was rooted in my awareness of how much time is needed. I resented that (as I saw it) too much of that finite resource was being consumed by the acquisition of a few foundational basics because of what I still do see as pedagogical flaws, but that’s an academic point which doesn’t reduce my gratitude for the existence of these learning resources, any possible criticism of which I will, from now on, keep to myself.

points
Submitted by royfischer
over 8 years

1 comments

Roy over 8 years

It does change the perspective, you are right about that. One thing that does not change is learner accountability. We can blame the teacher for our failure, but it is still our failure, not the teacher’s. In a society that is bent upon entitlement, we soon learn it does not apply to learning. We are not entitled to knowledge, we must earn it with work and due diligence. Good that you have taken a second look at this. :-)