Solution 1 :

You can do this.

document.getElementsByClassName("coupon-container")[0].setAttribute("onclick", "new_function();");

Problem :

I Try to find a solution for a client but i wont get out.
The problem is that i cant edit the HTML, so i try to get a work-around with Javascript


<!-- This section must be hide in CSS or something --> 
                    <div class="coupon-container">
                        <input class="input-text" type="text" id="coupon_code" name="coupon_code" value="">
                                                <div class="btn-apply">
                            <button type="button" title="Toepassen" class="button-coupon medium" onclick="discountForm.submit(false)" value="Toepassen"><span><span>Toepassen</span></span></button>
                        </div>
                    </div><!-- end of section Hiding CSS --> 
                </div>

This is the
HTML code and i want to add a

onclick=”new_function();

OLD CODE
<div class="coupon-container">

NEW CODE
<div class="coupon-container" onclick="new_function();>

Is this possible? Keep in mind that i need a Javascript, so i cant edit the HTML directly from CMS.

I Hope you guys can help me out.

Kind regards

Comments

Comment posted by Add onclick event to newly added element in JavaScript

Does this answer your question?

By