Monday, February 1, 2016

after() / before()

Sometimes you want to insert something into the DOM, but you don't have any good hooks to do it with; append() or prepend() aren't going to cut it and you don't want to add an extra element or id. These two functions might be what you need. They allow you to insert elements into the DOM just before or after another element, so the new element is a sibling of the older one. 1 2 $('#child').after($('
')).text('This becomes a sibling of #child')); $('#child').before($('
')).text('Same here, but this is go about #child')); You can also do this if you're working primarily with the element you want to insert; just use the insertAfter() or insertBefore functions. 1 $('
I\'ll be a sibling of #child
').insertAfter($('#child'));

What is the differebce between using == and === ?


The == or != operator perform an automatic type conversion in Javascript if you want to compare between two values like this '10' == 10 , for this example we already know that 10 is number but '10' is not number it is string but when we compare that values one of them will convert to the same datatype we can say maybe '10' convert to number before compare, anyway we don't recommend to use this.
The === or !== operator will not perform any conversion mean it compares both value and datatype which could be faster than using == operator.
Example:[10] === 10 // is false[10] == 10 // is true'10' == 10 // is true'10' === 10 // is false [] == 0 // is true [] === 0 // is false '' == false // is true but true == "a" is false '' === false // is false