Elements

2 minutes
Share the link to this page
Copied
  Completed
Selects all elements with the given tag name.

Transcript

Hello, in this jQuery video, we are going to look at the element selector. So the element selector allows us to basically select a particular type of element. We don't really have any, you know, major elements, let's just add a div, it can be any element you want. So this is called Hello, world. And save that. Now in our custom JavaScript file, to select something, you put dollar, open curly bracket, then you put quotation marks and then the element you've selected, so they're like so and we're gonna, you know, it's gonna be something simple.

It's gonna be dot click, I'm gonna cover all of the different features that you can apply when selecting an element at a later date in a future video, so feel free to check them out. Okay, and the general format is this so you are running a function This function will do something. I'm simply gonna console log something out saying div id. Save that. And reload, click it, it says div is clicked. Let me add a p tag or a paragraph tab.

I'm gonna click the text or graph inside. And if I reload fuckity, it doesn't do anything because this is selecting a div. But let me show you something else. If I create another div, nobody's going to say, second, Dave, save it. Reload. If I click that, it triggers the Dave click.

And if I click the first one, it triggers this click as well it triggers this you know piece of code. That's fine if you want or Dave elements to trigger The same sort of selector code. But if you don't, I'll recommend watching one of my future video in a few videos time, I'm going to show you how to select just individual elements. So you can make sure the user is clicking the right one, and we'll get the right response. So that's it for the element selector allows you to you know, select an element and do something with it. In this case, check if it's been clicked, instead of using the JavaScript version, which would be on click equals and then you know name of the function, something like that.

This isn't as elegant. And this just keeps it in one separate file. And you can do a lot more code here and you could do selected within selected which are covered in a separate video. Thanks for watching, and I look forward to seeing you in the next jQuery video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.