Tuesday 24 July 2012

Is your hide div is exist in body before you show?

Today I worked on a task in which a hide div has to be display on onclick  event binding.But i was irritated when the div is not showing through show().

Reason: div to be show is not placed in body (because of some if condition or may be it placed in some function that is not called inside body)

Sunday 22 July 2012

difference in empty() and remove()


  • Empty will remove all the contents of the selection.
  • Remove will remove the selection and its contents.
Consider:
<div>
    <p><strong>foo</strong></p>
</div>

$('p').empty();  // --> "<div><p></p></div>"

// whereas,
$('p').remove(); // --> "<div></div>"

Friday 20 July 2012

Applying validation using Javascript on event binding always use button rather than submit

Reason : Since while checking negative condition on validation  we must restrict the form to load or submit.To stop loading of form  we can't use submit  button because it loads form atleast once

Thursday 19 July 2012

return false exit from function

We thought return false only stops the form to submit ..but it is not true actually it stops the function to return the value that function wants to return and also exit the program control from the function (Its a programming principle that when a function return false then control exit the function).

Wednesday 18 July 2012

Calling two function on single event

We can call multiple functions on a single event such as onclick,onsubmit etc by seperating with semicolon sign ;....like this

<a href="..." onclick="fun1();fun2();">

Alert: -1.Make sure the first function not submit the form otherwise second function will not execute and
2. same thing happens when first function have explicit return statement that time also second function may not execute.

Thursday 5 July 2012

Difference in onclick and onClick()

Event attributes in HTML are not case sensitive, so onclickonClick and ONCLICK all work. It is common practice to write attributes in lowercase: onclicknote that javascript itself is case sensitive, so if you write document.getElementById("...").onclick = ..., then it must be all lowercase.

Wednesday 4 July 2012

Dont write explicitly javascript:Calling a return type js function on event binding


Don't write javascript while returning a function on some event binding.

Ex-<input type="button" value="Submit" onclick="return javascript:ConfirmClientForRelocation()"/>

Here google chrome is not catch this so use instead

Ex-<input type="button" value="Submit" onclick="return ConfirmClientForRelocation()"/>