Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 402
  • 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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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