Sampuran programming
Belief in Clean and Quality of code
Q) Difference between $(this) and 'this' in jQuery?
A) this and $(this) refers to the same element. The only difference is the way they are used. 'this' is used in traditional sense, when 'this' is wrapped in $() then it becomes a jQuery object and you are able to use the power of jQuery.
$(document).ready(function(){
$(' ').mouseover(function(){
alert($(this).text());
});
});
this is an object but since it is not wrapped in $(), we can't use jQuery method and use the native JavaScript to get the value of span element.
$(document).ready(function(){
$(' ').mouseover(function(){
alert(this.innerText);
});
});
Q) What is the difference between .empty(), .remove() and .detach() methods in jQuery?
A): All these methods .empty(), .remove() and .detach() are used for removing elements from DOM but they all are different.
empty(): This method removes all the child element of the matched element where remove() method removes set of matched elements from DOM.
remove(): Use .remove() when you want to remove the element itself, as well as everything inside it. In addition to the elements themselves, all bound events and jQuery data associated with the elements are removed.
detach(): This method is the same as .remove(), except that .detach() keeps all jQuery data associated with the removed elements. This method is useful when removed elements are to be reinserted into the DOM at a later time.
function a(){
alert('A');
}
function a(){
alert('AA');
}
a();
What will be the output?
1) alert A.
2) alert AA.
3) Program will throw error re-declaration function a.
Click here to claim your Sponsored Listing.
Category
Contact the business
Website
Address
160055
Opening Hours
| Monday | 9am - 5pm |
| Tuesday | 9am - 5pm |
| Wednesday | 9am - 5pm |
| Thursday | 9am - 5pm |
| Friday | 9am - 5pm |
| Saturday | 9am - 5pm |