Noteworthy Conventions
Conventions used here in the Novice Notes JavaScript Quick Reference may be recognized as follows:
- W3C DOM Core:
Due to the nature of the WordPress web log software, i will attempt to organize this reference in a hierarchical manner– therefore, this Top-Level page has its own child-pages (see web log Page navigation). Each of those sub-pages which are listed as a Method should contain a<dl>element in which the The<dt>field will indicate the title of that Method. Where applicable, the title shown there will be a hyperlink to the W3C DOM Core reference2
Cursory Look: Definitions in Disarray
Disclaimer: as this reference has been compiled as i’m going along, learning the language syntax and how to use it , i apologize that much of it may not be thoughtfully formatted for your viewing convenience. i intend to re-format the document in the future (in particular, the items listed below, and in the “Sub-Pages” navigable via the pages menu).
- innerHTML (a DOM thing?)
- Summary
innerHTML sets or gets all of the markup and content within a given element.
Syntax
var markup = element.innerHTML;element.innerHTML = markup;markupis a string that contains the element’s content (including child elements) as raw HTML. For example,
.
"<p>Some text</p>"
Example
// HTML: // <div id="d"><p>Content</p> // <p>Further Elaborated</p> // </div>d = document.getElementById("d");dump(d.innerHTML); // the string "<p>Content</p><p>Further Elaborated</p>" // is dumped to the console windowNotes
Though not actually a part of the W3C DOM specification, this property provides a simple way to completely replace the contents of an element. For example, the entire contents of the document body can be deleted by:
document.body.innerHTML = "";
// Replaces body content with an empty string.
The innerHTML property of many types of elements—including BODY or HTML—can be returned or replaced. It can be used to view the source of a page that has been modified dynamically:
NOTE: developer.mozilla.org Example ommitted here. Please visit the source page for the complete text
As there is no public specification for this property, implementations differ widely. For example, when text is entered into a text input, IE will change the value attribute of the input’s innerHTML property but Gecko browsers do not.
It should never be used to write parts of a table—W3C DOM methods should be used for that—though it can be used to write an entire table or the contents of a cell.
Specification
DOM Level 0. Not part of any standard.
References
- JavaScript Operators
-
- String Concatenation(1)
-
In addition to the comparison operators, which can be used on string values, the concatenation operator (
+) concatenates two string values together, returning another string that is the union of the two operand strings. For example,"my " + "string"returns the string"my string".The shorthand assignment operator
+=can also be used to concatenate strings. For example, if the variablemystringhas the value “alpha“, then the expressionmystring += "bet"evaluates to “alphabet” and assigns this value tomystring. - typeof
- The
typeofoperator is used in either of the following ways:-
typeof operand -
typeof (operand)
The
typeofoperator returns a string indicating the type of the unevaluated operand.operandis the string, variable, keyword, or object for which the type is to be returned. The parentheses are optional.
Suppose you define the following variables:var myFun = new Function("5+2") var shape="round" var size=1 var today=new Date()The
typeofoperator returns the following results for these variables:typeof myFun is object typeof shape is string typeof size is number typeof today is object typeof dontExist is undefined
-
- :: next javascript operator ::
- :: next description ::
- Special Operators:(1)
-
- Conditional « ?: »
- The conditional operator is the only JavaScript operator that takes three operands. This operator is frequently used as a shortcut for the
ifstatement.Syntax:
condition ? expr1 : expr2Parameters:
conditionAn expression that evaluates to
trueorfalse.expr1,expr2Expressions with values of any type.
Description:
If
conditionistrue, the operator returns the value ofexpr1; otherwise, it returns the value ofexpr2. For example, to display a different message based on the value of theisMembervariable, you could use this statement:document.write ("The fee is " + (isMember ? "$2.00" : "$10.00")) - :: special op … ::
- :: special definition … ::
- Operator Precedence(1)
-
Mozilla : Core JavaScript 1.5 – Operator Precedence
The table below is an exact copy(1) of the Operator Precedence Table found at Mozilla.org
In accordance with relevant discussion, this table was reversed to list operators in decreasing order of priority.
Operator type Individual operators member . [] call / create instance () new negation/increment ! ~ - + ++ – typeof void delete multiply/divide * / % addition/subtraction + - bitwise shift << >> >>> relational < <= > >= in instanceof equality == != === !== bitwise-and & bitwise-xor ^ bitwise-or | logical-and && logical-or || conditional ?: assignment = += -= *= /= %= <<= >>= >>>= &= ^= |= comma , Table 3.1: Operator precedence
A more detailed version of this table, complete with links to additional details about each operator, may be found in the Reference section.
Definitive Javascript References
Listed below are some of the most widely referenced and accepted JavaScript Resources available.
Mozilla.org – the Core JavaScript 1.5 Guide
the Re-Introduction to JavaScript
Mozilla Dot Org is Important to JavaScript for a very valid reason: they invented it! Well, not exactly, but essentially Mozilla is what became of Netscape Navigator (or, one might say that the Netscape Navigator is code-named Mozilla). If you have a deeper interest in the details, another important element to the history, the 3rd-party SillyDog701 maintains a concise history of Netscape Navigator and Mozilla.org
Dynamic Drive
Dynamic Drive is a popular Users’ Forum where a lot of relevant scripts and references are available. the Forum is a great resource for anyone who is learning and actively coding in JavaScript.
JavaScript Kit
Similar to DynamicDrive, JavaScript Kit is arguably the most popular starting point for students of javascript, and those who just want to “grab a pre-made script” for use in a web site.
1
Operators:Core JavaScript 1.5 Guide. Mozilla Dot Org, et al. Rev. Mar-01, 2007. Available at: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Operators. Accessed: Mar-21, 2007
2
the W3C Document Object Model Core reference: [ http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113 ]
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.
You must be logged in to post a comment.