I have the following piece of code:
$(document).ready(function() {
$("a[href*='window']").on("mouseover", function() {
$(this).css('color', 'green');
});
$("a:eq(2)").click(function() {
$(this).attr("href", "#window_1");
});
});
a {
padding-left: 20px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<a href="#1_window">link 1</a>
<a href="#1_window_1">link 2</a>
<a href="#">link 3 (click to add substring "window")</a>
Here I'm basically trying to apply some css to a
tags having the substring 'window' in their 'href' attribute on 'mouseover' event.
The code works fine for ones with predefined attribute (having the specified substring) but fails for dynamically added attributes.
How do I solve this issue?