Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

jQuery: Create div with attribute that contains dash

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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…

792 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