src/html-amend.js
function insertAttribute(input, element, attributeName, attributeValue) {
            // Sanity check
            verifyParameterIsDefined(input, 'input', insertAttribute.name);
            verifyParameterIsDefined(element, 'element', insertAttribute.name);
            verifyParameterIsDefined(attributeName, 'attributeName', insertAttribute.name);

            return insertAfter(normalizeValue(input), normalizeRegExp(`<${normalizeValue(element)}[^\>]*`), ` ${normalizeValue(attributeName)}="${normalizeValue(attributeValue)}"`);
        }
function insertAttribute(input, element, attributeName, attributeValue) {
            // Sanity check
            verifyParameterIsDefined(input, 'input', insertAttribute.name);
            verifyParameterIsDefined(element, 'element', insertAttribute.name);
            verifyParameterIsDefined(attributeName, 'attributeName', insertAttribute.name);

            return insertAfter(normalizeValue(input), normalizeRegExp(`<${normalizeValue(element)}[^\>]*`), ` ${normalizeValue(attributeName)}="${normalizeValue(attributeValue)}"`);
        }
function insertAttribute ( input , element , attributeName , attributeValue ) { // Sanity check verifyParameterIsDefined ( input , 'input' , insertAttribute . name ) ; verifyParameterIsDefined ( element , 'element' , insertAttribute . name ) ; verifyParameterIsDefined ( attributeName , 'attributeName' , insertAttribute . name ) ; return insertAfter ( normalizeValue ( input ) , normalizeRegExp ( ` ${ normalizeValue ( element ) } \> ` ) , ` ${ normalizeValue ( attributeName ) } ${ normalizeValue ( attributeValue ) } ` ) ; }
Inserts an attribute into the input string within the first occurrence of the element open tag.

@param {String|Function} input the input string
@param {String|Function} element the element tag to modify
@param {String|Function} attributeName the attribute name to add
@param {String|Function} [attributeValue] the attribute value to add
@return {String} a String which has the attribute added into the first occurrence of the element open tag
@throws {String} when input, element or attributeName are not defined
Inserts an attribute into the input string within the first occurrence of the element open tag .