• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 428
  • Last Modified:

jQuery: Create div with attribute that contains dash

Using jQuery, how can I create a div with an attribute of: "data-rel-xyz"?

This does not work:

$('<div/>', {
    data-rel-xyz: '555',
    xyz: '123'
}).appendTo('body');

Open in new window

0
hankknight
Asked:
hankknight
1 Solution
 
GaryCommented:
You need to enclose the attribute title (the dash breaks the name otherwise) e.g.

'data-rel-xyz' : '555',
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now