I'm trying to set a variable attribute name, ie <a data-33="string">
, with 33 being a random number generated by Math.random().
I have tried:
var randomNum1 = Math.floor(Math.random() * (200 - 100 + 1)) + 100;
var attrb = 'data-' + randomNum1.toString();
$(this).attr({
attrb : 'someString',
attrb2 : 'someString'
});
But instead of adding an attribute of data-randomNumber="someString", it adds attrb="someString"
I'm trying to pass multiple attributes. I know I'm missing a basic javascript concept, but any help would be appreciated!