Why is ID not being detected?

Hi, I have a container open on click and want it to close on clicks outside of it… I think I’m having trouble with (this)

html like so

<div id="extra-mo" class="cd-label">blablabla</div>

Did have the JQ if say if this == offer container or extra mo… but broke it up to try work out why it isnt being detected…

$('html').click(function() {
 var div = $(this);

 if (div.attr("id") == "offer-container"){
	 console.log('clicked in c or button');
 if (this.id == ("extra-mo")){
	 console.log('clicked in c or button');
	 console.log('not in');
	$("#offer-container").css ({"display":"none"}); 
    $("#outter-c").css ({"opacity":"1"}); 


I always get console logs of not in… can anyone say where Ive gone wrong please


    var div= $('#extra-mo');

    if (!div.is(event.target)){
        console.log('This is not #extra-mo');


Brilliant, thanks megazoid…
I thought (this) would refer to where the click happened…seems not.

event is getting passed as an object - I get that.
the .target is what?

thx thx

See the docs http://api.jquery.com/event.target/
and http://api.jquery.com/category/events/event-object/

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.