Avicinnian
Avicinnian

Reputation: 1830

Div with a jQuery click event bound to it is not firing when clicked?

It could be a rookie mistake, but I've gone over my code enough times doing things such as; pre-pending .select-delete with div, attempted to use document.write("Hello") to see if the event was firing or not.

Here's a link to my jsFiddle: http://jsfiddle.net/gPF8X/5/

I really have no idea what's going on :(.

Any help would be greatly appreciated!

Edit: Linked to the incorrect JSFiddle, relinked to the correct one.

Upvotes: 1

Views: 110

Answers (3)

Dan
Dan

Reputation: 11069

I know you already accepted my other answer, but I just want to add for the record that there is another way to do it. Specifically, this seems like one of those cases where jQuery is less helpful rather than more. What I would do is change your HTML so the element names were also given as IDs, and then write it like so:

document.getElementById('g_country['+value+']').disabled = true;
document.getElementById('g_url['+value+']').disabled = true;

Upvotes: 0

Dan
Dan

Reputation: 11069

The trigger is firing, but your code is not running because of an error - you're not quoting the string 'id' so it's an undefined value. Use your browser's debugger tool - it will help for this sort of thing.

Beyond that though, I can't say anything further because it's not clear what the desired result is.

Edit There's another issue as well - the selector is not working. You can't use the [ and ] character unquoted inside a jQuery comparison like that. The simplest solution is just not to have those characters in your input names. But you can also use escaping like so: $('select[name=g_country\\['+value+'\\]]').

Upvotes: 1

marissajmc
marissajmc

Reputation: 2603

There is no - in your div class name.

<div id="1" class="selectdelete"></div>

$('.select-delete').click( function() {

Got it - id needs to be wrapped in quotes.

var value = $(this).attr('id');

Upvotes: 2

Related Questions