Reputation: 1222
I have this jQuery code as part of a loop to generate divs and set properties for each div.
var names = $('<div/>', {
id: load1array[j],
'class': 'bold',
html: load1array[j]
});
I want to add a title attribute for each div, but I forgot the syntax. I have tried the codes below but they don't appear to be the right syntax.
var names = $('<div/>', {
id: load1array[j],
'class': 'bold',
//attr:('title','text here'),
//title:'text here' ,
//'title':'text here' ,
html: load1array[j]
})//.attr( "title", "text here" );
TIA
Edit:
I also saw the answer here Creating a div element in jQuery, which shows that the code that includes the title attribute
jQuery('<div/>', {
id: 'foo',
href: 'http://google.com',
title: 'Become a Googler',
rel: 'external',
text: 'Go to Google!'
}).appendTo('#mySelector');
But it did not work as I have tried, following the answer's included links, perhaps the title attribute does not work with <div>
tags, but rather <a>
tags.
Upvotes: 0
Views: 550
Reputation: 8352
Try this:
var names = $('<div/>', {
id: load1array[j],
'class': 'bold',
html: load1array[j]
});
names.attr("title", "text here");
Upvotes: 1