javascript - HTML5 combine commonly-used attributes into super-attribute? -


i have lot of buttons like:

<button type="button" class="btn btn-info" data-toggle="modal" data-target="#qq" data-req="foo">foo</button> <button type="button" class="btn btn-info" data-toggle="modal" data-target="#qq" data-req="bar">bar</button> <button type="button" class="btn btn-info" data-toggle="modal" data-target="#qq" data-req="baz">baz</button> 

i'd avoid repetition; there way define sort of single attribute expand several other attributes? example might end looking like

super x = 'type="button" class="btn btn-info" data-toggle="modal" data-target="#qq"';  <button super="x" data-req="foo">foo</button> <button super="x" data-req="bar">bar</button> <button super="x" data-req="baz">baz</button> 

nb. of course done server-side scripting i'm hoping avoid that. using bootstrap 3.3.4 , these buttons trigger bootstrap modal.

this works:

<button type="button" class="x" data-req="foo">foo</button> <button type="button" class="x" data-req="bar">baz</button> <button type="button" class="x" data-req="baz">baz</button> 

and in javascript section

$("button.x").addclass("btn btn-info"); $("button.x").attr("data-toggle", "modal"); $("button.x").attr("data-target", "#qq"); 

this removes of repetition still wondering if there more elegant and/or runtime-efficient way.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -