Link to home
Start Free TrialLog in
Avatar of MJ
MJFlag for United States of America

asked on

JS Code to Attach to Specific Element?

What would be the Javascript code to attach and event listener to this element?
<button type="button" class="btn btn-mobile btn-tertiary btn-grp-back mt-5" data-name="btn-grp-back">Back</button>

Open in new window

Here is a bigger picture of the structure.  User generated image
Thanks!
Avatar of lenamtl
lenamtl
Flag of Canada image

Hi,

you can do something like this

<button onclick="goBack()" class="btn btn-default" > Go back </button>
										
function goBack() {
		window.history.go(-1);
}

Open in new window


or like this with an ID

<button id="goback" class="btn btn-default" > Go back </button>

$('#goback').click(function() {
		window.history.go(-1);
});

Open in new window

Avatar of MJ

ASKER

I can't do that. I have to inject code via a TMS so I need to attach an event listener. 
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial