jQuery: The Write Less, Do More JavaScript Library

Event on every click on the page, except one element.

View: New views
8 Messages — Rating Filter:   Alert me  

Event on every click on the page, except one element.

by NMarcu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello all,

    I want to do something like this:

    On every click event, on the page, but except on specific element,
with id="elem_id" to do something. The element with id="elem_id" need
to update a table. And when I click on something else, that is not the
element with id="elem_id" I want that table to come back on the
original form. I'm intresting only in the jquery syntax, how can I
select all page, without a specific element, on click event.

Re: Event on every click on the page, except one element.

by Leonardo K :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

$(document).ready(function(){
    $('body').click(function(e){
        var elem = e.target;
        if ( $(elem).attr('id') != "elem_id" ){
            //do something
        }else{
            //do something
        }
    });
});

On Fri, Nov 6, 2009 at 14:13, NMarcu <marcu.nicolae@...> wrote:
Hello all,

   I want to do something like this:

   On every click event, on the page, but except on specific element,
with id="elem_id" to do something. The element with id="elem_id" need
to update a table. And when I click on something else, that is not the
element with id="elem_id" I want that table to come back on the
original form. I'm intresting only in the jquery syntax, how can I
select all page, without a specific element, on click event.


Re: Event on every click on the page, except one element.

by Leonardo K :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Example: http://jsbin.com/iraqo
Edit to view the source: http://jsbin.com/iraqo/edit

On Fri, Nov 6, 2009 at 14:22, Leonardo K <leok85@...> wrote:
$(document).ready(function(){
    $('body').click(function(e){
        var elem = e.target;
        if ( $(elem).attr('id') != "elem_id" ){
            //do something
        }else{
            //do something
        }
    });
});


On Fri, Nov 6, 2009 at 14:13, NMarcu <marcu.nicolae@...> wrote:
Hello all,

   I want to do something like this:

   On every click event, on the page, but except on specific element,
with id="elem_id" to do something. The element with id="elem_id" need
to update a table. And when I click on something else, that is not the
element with id="elem_id" I want that table to come back on the
original form. I'm intresting only in the jquery syntax, how can I
select all page, without a specific element, on click event.



Re: Event on every click on the page, except one element.

by NMarcu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Can I do something like this:
$(document).ready(function(){
    $('body').click(function(e){
        var elem = e.target;
        if ( $(elem).attr('class') != "elem_class" ){
            //do something
        }else{
            //do something
        }
    });
});

I need to select by class? If I have more elements in a div with id="div_id", can I use this id, and all elements will be passend from click event?

2009/11/6 Leonardo K <leok85@...>
Example: http://jsbin.com/iraqo
Edit to view the source: http://jsbin.com/iraqo/edit


On Fri, Nov 6, 2009 at 14:22, Leonardo K <leok85@...> wrote:
$(document).ready(function(){
    $('body').click(function(e){
        var elem = e.target;
        if ( $(elem).attr('id') != "elem_id" ){
            //do something
        }else{
            //do something
        }
    });
});


On Fri, Nov 6, 2009 at 14:13, NMarcu <marcu.nicolae@...> wrote:
Hello all,

   I want to do something like this:

   On every click event, on the page, but except on specific element,
with id="elem_id" to do something. The element with id="elem_id" need
to update a table. And when I click on something else, that is not the
element with id="elem_id" I want that table to come back on the
original form. I'm intresting only in the jquery syntax, how can I
select all page, without a specific element, on click event.





--
All the best,

Nicolae MARCU

Re: Event on every click on the page, except one element.

by Leonardo K :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If your id is a container u need to traverse the element to find the parent.

<div id="aaa">
    <div>
        <p>asdasd</p>
    </div>
</div>

If you click the asdasd will return the p element. U could do $(elem).closest('#aaa') to find the element that you want.

On Fri, Nov 6, 2009 at 14:45, Nicu Marcu <marcu.nicolae@...> wrote:
Can I do something like this:

$(document).ready(function(){
    $('body').click(function(e){
        var elem = e.target;
        if ( $(elem).attr('class') != "elem_class" ){

            //do something
        }else{
            //do something
        }
    });
});

I need to select by class? If I have more elements in a div with id="div_id", can I use this id, and all elements will be passend from click event?

2009/11/6 Leonardo K <leok85@...>

Example: http://jsbin.com/iraqo
Edit to view the source: http://jsbin.com/iraqo/edit


On Fri, Nov 6, 2009 at 14:22, Leonardo K <leok85@...> wrote:
$(document).ready(function(){
    $('body').click(function(e){
        var elem = e.target;
        if ( $(elem).attr('id') != "elem_id" ){
            //do something
        }else{
            //do something
        }
    });
});


On Fri, Nov 6, 2009 at 14:13, NMarcu <marcu.nicolae@...> wrote:
Hello all,

   I want to do something like this:

   On every click event, on the page, but except on specific element,
with id="elem_id" to do something. The element with id="elem_id" need
to update a table. And when I click on something else, that is not the
element with id="elem_id" I want that table to come back on the
original form. I'm intresting only in the jquery syntax, how can I
select all page, without a specific element, on click event.





--
All the best,

Nicolae MARCU


Re: Event on every click on the page, except one element.

by NMarcu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have a div like this:
<div id="tab_informations">
                <fieldset>
                    <label for="name">Name</label>
                    <input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all"/>
                    <label for="password">Password</label>
                    <input type="password" name="password" id="password"  class="text ui-widget-content ui-corner-all"/>
                    <label for="email">Email</label>
                    <input type="text" name="email" id="email" class="text ui-widget-content ui-corner-all" />
                    <label for="firstname">First Name</label>
                    <input type="text" name="firstname" id="firstname" class="text ui-widget-content ui-corner-all" />
                    <label for="lastname">Last Name</label>
                    <input type="text" name="lastname" id="lastname" class="text ui-widget-content ui-corner-all"  />
                </fieldset>
  </div>

How can I set to not react on click event on all elements on this div?

Like this, not working:

$('body').click(function(e){
                    var elem = e.target;
                   
                    if ( $(elem).attr('id') != "tab_informations"{
                   //do something
                    }
});

2009/11/6 Leonardo K <leok85@...>
If your id is a container u need to traverse the element to find the parent.

<div id="aaa">
    <div>
        <p>asdasd</p>
    </div>
</div>

If you click the asdasd will return the p element. U could do $(elem).closest('#aaa') to find the element that you want.


On Fri, Nov 6, 2009 at 14:45, Nicu Marcu <marcu.nicolae@...> wrote:
Can I do something like this:

$(document).ready(function(){
    $('body').click(function(e){
        var elem = e.target;
        if ( $(elem).attr('class') != "elem_class" ){

            //do something
        }else{
            //do something
        }
    });
});

I need to select by class? If I have more elements in a div with id="div_id", can I use this id, and all elements will be passend from click event?

2009/11/6 Leonardo K <leok85@...>

Example: http://jsbin.com/iraqo
Edit to view the source: http://jsbin.com/iraqo/edit


On Fri, Nov 6, 2009 at 14:22, Leonardo K <leok85@...> wrote:
$(document).ready(function(){
    $('body').click(function(e){
        var elem = e.target;
        if ( $(elem).attr('id') != "elem_id" ){
            //do something
        }else{
            //do something
        }
    });
});


On Fri, Nov 6, 2009 at 14:13, NMarcu <marcu.nicolae@...> wrote:
Hello all,

   I want to do something like this:

   On every click event, on the page, but except on specific element,
with id="elem_id" to do something. The element with id="elem_id" need
to update a table. And when I click on something else, that is not the
element with id="elem_id" I want that table to come back on the
original form. I'm intresting only in the jquery syntax, how can I
select all page, without a specific element, on click event.





--
All the best,

Nicolae MARCU




--
All the best,

Nicolae MARCU

Re: Event on every click on the page, except one element.

by mkmanning :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

user .is() and pass selectors for the elements you want to match:

$(document).ready(function(){
        $('body').click(function(e){
                e = $(e.target);
                if(!e.is('.ui-widget-content,label,fieldset')){
                        console.log('test');
                }
        });
});

On Nov 6, 11:33 am, Nicu Marcu <marcu.nico...@...> wrote:

> I have a div like this:
> <div id="tab_informations">
>                 <fieldset>
>                     <label for="name">Name</label>
>                     <input type="text" name="name" id="name" class="text
> ui-widget-content ui-corner-all"/>
>                     <label for="password">Password</label>
>                     <input type="password" name="password" id="password"
> class="text ui-widget-content ui-corner-all"/>
>                     <label for="email">Email</label>
>                     <input type="text" name="email" id="email" class="text
> ui-widget-content ui-corner-all" />
>                     <label for="firstname">First Name</label>
>                     <input type="text" name="firstname" id="firstname"
> class="text ui-widget-content ui-corner-all" />
>                     <label for="lastname">Last Name</label>
>                     <input type="text" name="lastname" id="lastname"
> class="text ui-widget-content ui-corner-all"  />
>                 </fieldset>
>   </div>
>
> How can I set to not react on click event on all elements on this div?
>
> Like this, not working:
>
> $('body').click(function(e){
>                     var elem = e.target;
>
>                     if ( $(elem).attr('id') != "tab_informations"{
>                    //do something
>                     }
>
> });
>
> 2009/11/6 Leonardo K <leo...@...>
>
>
>
>
>
> > If your id is a container u need to traverse the element to find the
> > parent.
>
> > <div id="aaa">
> >     <div>
> >         <p>asdasd</p>
> >     </div>
> > </div>
>
> > If you click the asdasd will return the p element. U could do
> > $(elem).closest('#aaa') to find the element that you want.
>
> > On Fri, Nov 6, 2009 at 14:45, Nicu Marcu <marcu.nico...@...> wrote:
>
> >> Can I do something like this:
>
> >> $(document).ready(function(){
> >>     $('body').click(function(e){
> >>         var elem = e.target;
> >>         if ( $(elem).attr('class') != "elem_class" ){
>
> >>             //do something
> >>         }else{
> >>             //do something
> >>         }
> >>     });
> >> });
>
> >> I need to select by class? If I have more elements in a div with
> >> id="div_id", can I use this id, and all elements will be passend from click
> >> event?
>
> >> 2009/11/6 Leonardo K <leo...@...>
>
> >> Example:http://jsbin.com/iraqo
> >>> Edit to view the source:http://jsbin.com/iraqo/edit
>
> >>> On Fri, Nov 6, 2009 at 14:22, Leonardo K <leo...@...> wrote:
>
> >>>> $(document).ready(function(){
> >>>>     $('body').click(function(e){
> >>>>         var elem = e.target;
> >>>>         if ( $(elem).attr('id') != "elem_id" ){
> >>>>             //do something
> >>>>         }else{
> >>>>             //do something
> >>>>         }
> >>>>     });
> >>>> });
>
> >>>> On Fri, Nov 6, 2009 at 14:13, NMarcu <marcu.nico...@...> wrote:
>
> >>>>> Hello all,
>
> >>>>>    I want to do something like this:
>
> >>>>>    On every click event, on the page, but except on specific element,
> >>>>> with id="elem_id" to do something. The element with id="elem_id" need
> >>>>> to update a table. And when I click on something else, that is not the
> >>>>> element with id="elem_id" I want that table to come back on the
> >>>>> original form. I'm intresting only in the jquery syntax, how can I
> >>>>> select all page, without a specific element, on click event.
>
> >> --
> >> All the best,
>
> >> Nicolae MARCU
>
> --
> All the best,
>
> Nicolae MARCU

Re: Event on every click on the page, except one element.

by mkmanning :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

and you could use
...
if(!e.is('#tab_informations *')){
...
On Nov 6, 11:50 am, mkmanning <michaell...@...> wrote:

> user .is() and pass selectors for the elements you want to match:
>
> $(document).ready(function(){
>         $('body').click(function(e){
>                 e = $(e.target);
>                 if(!e.is('.ui-widget-content,label,fieldset')){
>                         console.log('test');
>                 }
>         });
>
> });
>
> On Nov 6, 11:33 am, Nicu Marcu <marcu.nico...@...> wrote:
>
>
>
> > I have a div like this:
> > <div id="tab_informations">
> >                 <fieldset>
> >                     <label for="name">Name</label>
> >                     <input type="text" name="name" id="name" class="text
> > ui-widget-content ui-corner-all"/>
> >                     <label for="password">Password</label>
> >                     <input type="password" name="password" id="password"
> > class="text ui-widget-content ui-corner-all"/>
> >                     <label for="email">Email</label>
> >                     <input type="text" name="email" id="email" class="text
> > ui-widget-content ui-corner-all" />
> >                     <label for="firstname">First Name</label>
> >                     <input type="text" name="firstname" id="firstname"
> > class="text ui-widget-content ui-corner-all" />
> >                     <label for="lastname">Last Name</label>
> >                     <input type="text" name="lastname" id="lastname"
> > class="text ui-widget-content ui-corner-all"  />
> >                 </fieldset>
> >   </div>
>
> > How can I set to not react on click event on all elements on this div?
>
> > Like this, not working:
>
> > $('body').click(function(e){
> >                     var elem = e.target;
>
> >                     if ( $(elem).attr('id') != "tab_informations"{
> >                    //do something
> >                     }
>
> > });
>
> > 2009/11/6 Leonardo K <leo...@...>
>
> > > If your id is a container u need to traverse the element to find the
> > > parent.
>
> > > <div id="aaa">
> > >     <div>
> > >         <p>asdasd</p>
> > >     </div>
> > > </div>
>
> > > If you click the asdasd will return the p element. U could do
> > > $(elem).closest('#aaa') to find the element that you want.
>
> > > On Fri, Nov 6, 2009 at 14:45, Nicu Marcu <marcu.nico...@...> wrote:
>
> > >> Can I do something like this:
>
> > >> $(document).ready(function(){
> > >>     $('body').click(function(e){
> > >>         var elem = e.target;
> > >>         if ( $(elem).attr('class') != "elem_class" ){
>
> > >>             //do something
> > >>         }else{
> > >>             //do something
> > >>         }
> > >>     });
> > >> });
>
> > >> I need to select by class? If I have more elements in a div with
> > >> id="div_id", can I use this id, and all elements will be passend from click
> > >> event?
>
> > >> 2009/11/6 Leonardo K <leo...@...>
>
> > >> Example:http://jsbin.com/iraqo
> > >>> Edit to view the source:http://jsbin.com/iraqo/edit
>
> > >>> On Fri, Nov 6, 2009 at 14:22, Leonardo K <leo...@...> wrote:
>
> > >>>> $(document).ready(function(){
> > >>>>     $('body').click(function(e){
> > >>>>         var elem = e.target;
> > >>>>         if ( $(elem).attr('id') != "elem_id" ){
> > >>>>             //do something
> > >>>>         }else{
> > >>>>             //do something
> > >>>>         }
> > >>>>     });
> > >>>> });
>
> > >>>> On Fri, Nov 6, 2009 at 14:13, NMarcu <marcu.nico...@...> wrote:
>
> > >>>>> Hello all,
>
> > >>>>>    I want to do something like this:
>
> > >>>>>    On every click event, on the page, but except on specific element,
> > >>>>> with id="elem_id" to do something. The element with id="elem_id" need
> > >>>>> to update a table. And when I click on something else, that is not the
> > >>>>> element with id="elem_id" I want that table to come back on the
> > >>>>> original form. I'm intresting only in the jquery syntax, how can I
> > >>>>> select all page, without a specific element, on click event.
>
> > >> --
> > >> All the best,
>
> > >> Nicolae MARCU
>
> > --
> > All the best,
>
> > Nicolae MARCU