Clicking outside jQuery selector still activates function
Clicking outside jQuery selector still activates function
Follow these steps at JS Riddle to see the problem:
THE CODE BELOW
<div class="contentb">
<h1>testing hello world</h1>
<div class="point1">test</div>
</div>
point1 = '<div class="contentb"> <h1>Hello</h1><div class="point1"> test</div><div class="point2">Hey</div><h1>World</h1></div>';
point2 = '<div class="contentb"> <div class="point1"> test</div></div>';
var className = "Broken";
$(document).on('click', '.contentb [class]', function ()
$(this).fadeTo(250, 0.25, function ()
className = this.className;
$('.contentb').html(window[className]);
$(this).fadeTo(250, 1.00);
);
);
1 Answer
1
Your point1
and point2
variables should not contain contentb
div since you are appending the html to a element with class contentb
point1
point2
contentb
contentb
point1 = '<h1>Hello</h1><div class="point2"> test</div><div class="point2">Hey</div><h1>World</h1>';
point2 = '<div class="point1"> test</div>';
var className = "Broken";
$(document).on('click', '.contentb [class]', function ()
$(this).fadeTo(250, 0.25, function ()
className = this.className;
$('.contentb').html(window[className]);
$(this).fadeTo(250, 1.00);
);
);
Demo: Fiddle
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.