Solved

jQuery: Create div with attribute that contains dash

Posted on 2013-10-25
1
355 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

786 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