Skip to content

Actioning links within an injected element

Issue Description

If some HTML has been injected (using something like .append()) and it contains a link, that link won’t work when clicked due to it not being present when the document was ready.

Affected Browsers

  • all

Issue Type

How to Fix the Issue

To allow the link to be clickable, you have to change the scope of the link’s click action.

For example, if you inject a video container with a close button and the container element has a data attribute like data-wrap="video", your JS would look like the snippet below:

Fixed Code Snippets

$('[data-wrap="video"]').on('click', '.video-outer--close', function() {
	event.preventDefault();
	// CODE TO ACTION GOES HERE
});

Back to Issues List