javascript - jQuery attr() method to create a data dash attribute -


I am trying to understand why attribute for adding data-attributes (let's say an image) Name is required in quote I know that it needs to be done, but if a student asked me why I would not have the correct answer then take two examples below.

1.) I am exploring an explanation why dash is a problem.
2.) Is there a way to avoid it, so you do not need to put it in quotation marks? / P>

This does not work:

  $ ("img"). Attr ({alt: "picture of my cat", data -item: "pet", data-color: "orange",});   

This works

  $ ("img"). Attr ({alt: "photo of my cat", 'data-object': "pet", 'data-color': "orange",});   

3) The argument passed to the ARR () method is the true meaning of an object?
4. Is this object just a rule in the literal syntax which is not allowed to have a dash?

1). In object literals, the - symbol is not allowed as an identifier because it has zero operator in JavaScript.

2.) No, you have to use quotes.

3.) Yes.

4.) Yes, see 1.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -