filmov
tv
jQuery #id selector
Показать описание
Link for all dot net and sql server video tutorial playlists
Link for slides, code samples and text version of the video
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
In this video we will discuss
1. What are jQuery selectors
2. Different selectors in jQuery
3. #id selector in jquery
What are jQuery selectors
One of the most important concept in jQuery is selectors. jQuery selectors allow you to select and manipulate HTML elements.
Different selectors in jQuery
jQuery selectors allow you to select html elements in the DOM by
1. Element ID
2. Element Tag Name
3. Element Class Name
4. Element attribute
5. Element Attribute values and many more
Id selector in jquery
To find an HTML element by ID, use the jQuery #id selector
Example : The following example finds button with ID button1 and attaches the click event handler.
[html]
[head]
[title][/title]
[script type="text/javascript"]
$(document).ready(function () {
$('#button1').click(function () {
alert('jQuery Tuorial');
});
});
[/script]
[/head]
[body]
[input id="button1" type="button" value="Click Me" /]
[/body]
[/html]
Changes the background colour of the button to yellow
$(document).ready(function () {
$('#button1').css('background-color', 'yellow');
});
Important points to remember about jQuery #id selector
2. jQuery #id selector is the most efficient among all jQuery selectors. If you know the id of an element that you want to find, then always use the #id selector.
3. HTML element IDs must be unique on the page. jQuery #id selector returns only the first element, if you have 2 or more elements with the same ID.
[html]
[head]
[title][/title]
[script type="text/javascript"]
$(document).ready(function () {
$('#button1').css('background-Color', 'yellow');
});
[/script]
[/head]
[body]
[input id="button1" type="button" value="Click Me" /]
[input id="button1" type="button" value="Click Button" /]
[/body]
[/html]
[html]
[head]
[title][/title]
[script type="text/javascript"]
$(document).ready(function () {
if ($('#button1').length ] 0) {
alert('Element found')
}
else {
alert('Element not found')
}
});
[/script]
[/head]
[body]
[input id="button1" type="button" value="Click Me" /]
[/body]
[/html]
Link for slides, code samples and text version of the video
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
In this video we will discuss
1. What are jQuery selectors
2. Different selectors in jQuery
3. #id selector in jquery
What are jQuery selectors
One of the most important concept in jQuery is selectors. jQuery selectors allow you to select and manipulate HTML elements.
Different selectors in jQuery
jQuery selectors allow you to select html elements in the DOM by
1. Element ID
2. Element Tag Name
3. Element Class Name
4. Element attribute
5. Element Attribute values and many more
Id selector in jquery
To find an HTML element by ID, use the jQuery #id selector
Example : The following example finds button with ID button1 and attaches the click event handler.
[html]
[head]
[title][/title]
[script type="text/javascript"]
$(document).ready(function () {
$('#button1').click(function () {
alert('jQuery Tuorial');
});
});
[/script]
[/head]
[body]
[input id="button1" type="button" value="Click Me" /]
[/body]
[/html]
Changes the background colour of the button to yellow
$(document).ready(function () {
$('#button1').css('background-color', 'yellow');
});
Important points to remember about jQuery #id selector
2. jQuery #id selector is the most efficient among all jQuery selectors. If you know the id of an element that you want to find, then always use the #id selector.
3. HTML element IDs must be unique on the page. jQuery #id selector returns only the first element, if you have 2 or more elements with the same ID.
[html]
[head]
[title][/title]
[script type="text/javascript"]
$(document).ready(function () {
$('#button1').css('background-Color', 'yellow');
});
[/script]
[/head]
[body]
[input id="button1" type="button" value="Click Me" /]
[input id="button1" type="button" value="Click Button" /]
[/body]
[/html]
[html]
[head]
[title][/title]
[script type="text/javascript"]
$(document).ready(function () {
if ($('#button1').length ] 0) {
alert('Element found')
}
else {
alert('Element not found')
}
});
[/script]
[/head]
[body]
[input id="button1" type="button" value="Click Me" /]
[/body]
[/html]
Комментарии