Solved

jQuery: Create div with attribute that contains dash

Posted on 2013-10-25
1
343 Views
Last Modified: 2013-10-25
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
Comment
Question by:hankknight
1 Comment
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39601231
You need to enclose the attribute title (the dash breaks the name otherwise) e.g.

'data-rel-xyz' : '555',
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now