Pete wrote:
I'm trying to create a link that when clicked will produce an alert if
there are any visible divs (all .detail divs are hidden by default).
I have the following function but it doesn't seem I'm doing it
correctly; nothing happens regardless of the visibility status of the
divs.
$("a.saveConfig").click(function() {
$('div.detail').is(':visible'), (function () {
alert('Hey this works');
});
});
Is there a better way to do an if statement using JQuery selectors or
is there something I'm missing in my code?
The good thing about jQuery is that it has that if staterment kind of
built-in. If the selector doesn't match anything all the subsequently
chained functions are not executed. This only works with jQuery methods
of course but not with an alert like in your example:
$('div.detail:visible').append('I'm visible');
The string is appended only if div.detail is visible.
If you need to execute a non jQuery function you can still use the
each() method to avoid an if statement:
$('div.detail:visible').each(function() {
alert('Hey this works');
});
--Klaus