JS and a href className js write order with Run order string or variable embedding brackets instead of dot symbol attribute

Source: Internet
Author: User

JS and a href

Notice the semicolon ending in the href, closing the quotation marks.

<href= "javascript:;" > Empty link </a><href= "javascript: Alert (' a '); > popup </a>


Generally, it may be the code, generally let it empty. Empty can also use the pound sign ' # ', but not very well.


ClassName


<style>#div1{width:100px;Height:100px;Border:1px solid Black;}. Box{background:Red;}</style><Script>functiontored () {varOdiv=document.getElementById ('Div1'); Odiv. className ='Box'; Do not write class}</Script></Head><Body><inputtype= "button"value= "Turn red"onclick= "tored ()" /><DivID= "Div1">

1. getElementById is connected to the ID. But there is no way to connect with class.

getelementbyid () Returns a reference to the first object that owns the specified ID.
getelementsbyname () Returns a collection of objects with the specified name.
getElementsByTagName () Returns a collection of objects with the specified label name.

To use JS based/create classname index style. You need to add a level two attribute '. ClassName ' after getelement.

The label that was added after the specified ID is not only indexed from the ' pound ' index for the style of the ID, but also from the ' dot ' index for the class style.


2. getelement.classname = ' box '; The resulting change://The above example is the same as odiv for a different argument.

If the Class=xxx attribute is already in the <div> tag, then the event action leads to the function, CLASS=XXX will be modified to Class=box

If <div> does not have a class =xxx, it will be created incidentally when the script is executed.

Recall that if <div> does not specify a style = XXX, then Getelement.style.backgroud will also automatically create

GetElement. + Style/class/type/href/value and so on, want to change to add all can be very convenient and casual. I'm afraid you don't change.

This is just one way.

-There are getelement [' value '] in such a way that the brackets are quoted, and. The Out property of the (dot) is the same. It is generally not a special case to use ['] this way.

If ['] is to refer to a variable that assumes a = ' width ', then [' a '] becomes [' width '] so that it does not conform to the concept of getelement [' property '].

This time the processing method can be [a] without the quotation marks!

-All of them. can be replaced with [']

= box ;           //The following is an equivalent

odiv[' className '] = ' Box ' ;

Multilayer can also, odiv[' style ' [' width '] = ' 40px '

-When do I need to use [']? Function parameters can generally be passed to the value, sometimes to the property name on behalf of the property, it is necessary to use the ["]




JS Embedded HTML Run order:

-Performs an event action, executes a pointer to the JS function, and modifies the specified ID tag.

JS embedded HTML code to write the order:

-Want to change what effect, label Id/class to specify effect label, use. or # create {style}, call ID to write the logic to change CSS, trigger with event function.

js and a href className js write order with Run order string or variable embedding brackets instead of dot symbol for attribute

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.