Jquery: prevent click inside div from closing it … all elements?

This can be accomplished a number of ways, but my favorite is to name the trigger something like slider_1 and give it a class if slider Then give the actual slider an id of slider_1_content with a class if slider_content This will allow you to write something like.

This can be accomplished a number of ways, but my favorite is to name the trigger something like slider_1 and give it a class if .slider. Then give the actual slider an id of slider_1_content with a class if . Slider_content.

This will allow you to write something like: $(". Slider"). Click(function() { $("#" + this.

Attr("id") + "_content") ... }); You can then assign a close class to your close buttons/links and force them to close the parent slider like: $(". Close"). Click(function() { $(this).

Closest(". Slider_content").hide(); }).

.closest() (api.jquery. Com/closest) will, "Get the first ancestor element that matches the selector, beginning at the current element and progressing up through the DOM tree. " OP's elements are siblings not descendants.

------ Also, if the parent is the slider, the button will disappear. You could use .find() for parent buttons and child sliders. – Peter Ajtai Sep 23 '10 at 21:47 the .

Close button/link would be a descendant not a sibling. The first piece of code I posted address the trigger/slider issue. – Chris Pebble Sep 23 '10 at 21:56 Precisely.

If the close classed DIV is a descendant, then if you click on it, it will disappear (along with the slider contents)! If it's not a descendant, then closer() won't work. Try it out ==> jsfiddle.Net/tSTcL ---- PS: I don't get notified you commented back unless you start your message with @Peter.

Only authors and editors of a post get automatic notification. – Peter Ajtai Sep 23 '10 at 22:07 As the OP describes it he wants a close button inside the slider that will close the slider when clicked. Since he wants the button to appear in the slider the button would logically be a descendant of the slider.

– Chris Pebble Sep 23 '10 at 23:53 @Chris - The wording in the OP is somewhat unclear. I was inferring the meaning from the context and the title, "prevent click inside div from closing it " ------ Also, the sample HTML in the OP includes siblings..... But your guess is as good as mine ;) – Peter Ajtai Sep 23 '107 at 0:51.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions