Detect fieldset on mouse click JQUERY
i'm trying to add a single condition to the following Javascript that will stop the IF statement below evel开发者_StackOverflow社区uating to TRUE when user clicks inside a fieldset on the page.
I have tried allsorts but i'm guessing, I just tried adding " && !(e.target.isFieldSet))" but no joy. I've tried searching the web, anyone any ideas?
$(function() {
$('tr').live('click', function(e) {
//if not clicking an anchor tag or imag then assume user wants to go to details page
if ((!$(e.target).is('a')) && (!$(e.target).is('img')) && (!$(e.target).is('th')) && !(e.target.isTextEdit)) {
window.location = $("#AbsolutePath").val() + 'Waste.mvc/Details/' + $(this).attr('rowid');
}
});
});
I think you're looking for: !$(e.target).is('fieldset')
:
$(function() {
$('tr').live('click', function(e) {
//if not clicking an anchor tag or imag then assume user wants to go to details page
if ((!$(e.target).is('a')) && (!$(e.target).is('img')) && (!$(e.target).is('th')) &&
!(e.target.isTextEdit) && !$(e.target).is('fieldset')) {
window.location = $("#AbsolutePath").val() + 'Waste.mvc/Details/' + $(this).attr('rowid');
}
});
});
Example: http://jsfiddle.net/zbdRT/
However, I would argue that this is unmaintainable code. What if you need to add more tags (as you're doing right now). Something like this would be better:
if (!$(e.target).is("a, img, th, fieldset") && !e.target.isTextEdit)
or, you could store tags you want to ignore in an array that you can add to easily (this also makes the code a bit more expressive as to your intentions):
var excluded = ["a", "img", "th", "fieldset" ];
if (!$(e.target).is(excluded.join(", ")) && !e.target.isTextEdit)
精彩评论