Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Wednesday, December 16, 2015

How to select elements inside data-title with jQuery?

How to select elements inside data-title with jQuery?


I have html form like this: How can I select Gray / Silver from data-title?

 

I have wrote my code but not get the result. here

var data = $('.value').data('title');  console.log(data);  

Pls help me. Thanks in advace

Answer by void for How to select elements inside data-title with jQuery?


You should do

var data = $(".color-box.grey-silver-color-gradient").data("title");  console.log(data);  

Answer by user3850805 for How to select elements inside data-title with jQuery?


You can get attribute from tag by using attr from jquery

Example:

$('*[userattribute]').attr('userattribute');  

Answer by Dhunt for How to select elements inside data-title with jQuery?


You are selecting one element and then expecting to get a property of another element. $('.value') selects the parent div of the one you want to select.

You should try this, keeping specific to a child of $('.value'):

var data = $('.value .color-box.grey-silver-color-gradient').data("title");  console.log(data);  

jsfiddle: https://jsfiddle.net/o3ffptj3/

Answer by BG101 for How to select elements inside data-title with jQuery?


Your problem is the data-title is on the child element to .value.

try:-

var data = $('.value > .color-box').data('title');  console.log(data);  

or

var data = $('.color-box').data('title');  console.log(data);  

Answer by Amin Kodaganur for How to select elements inside data-title with jQuery?


You can select it by jquery method like this

$(selector).data('name');  

in your case like this

var data = $('.value > .color-box').data('name');  


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 71

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.