Idempotent JavaScript Values

Intro 

As an example, say you'd like to insert an arrow onto the page + perform a few css modifications. 

Pattern

The following pattern can be used to create idempotent JavaScript Values:

var $treatment = $('[data-ascend="arrow"]');

if (!$treatment.length){

var $arrow = $('<img data-ascend="arrow" src="https://media.ascend.ai/c/263105555-1/buy_arrow_01.png">')

.css({
"vertical-align": "middle",
"margin-left": "0.5em"
});

var $em = $("div.btn_buying_wrap a.btn_dshop em");

$arrow.insertAfter($em);

}

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk