user3424451 user3424451 - 4 months ago 27
Javascript Question

Dynamically Adding Data Roles (Collapsible data role)

I have a table with a table data-role that i would like to add a collapsible data role to. However i would have to add this dynamically through JQuery Mobile code.

$('#tabledataroleid').data('role','collapsible-set');
$('#tabledataroleid').data('role','collapsible');


Is there something off with my code? ^

Answer

You should be using the jQuery .attr() method to add attributes to an element. Try this:

$('#tabledataroleid').attr('role','collapsible-set');
$('#tabledataroleid').attr('role','collapsible');
Comments