0

I am having a hard time accessing a click even with my jQuery selector. Here is my HTML:

<li class="handle-bars">
    <span class="fa fa-bars pull-right text-primary m-t-10"></span>
    <span class="fa fa-cogs pull-right text-primary m-t-10" id="trigger-modal-editor" style="cursor:pointer" data-target="#modalSlideLeft" data-toggle="modal">     </span>
</li>

Here is my jQuery selector:

<script>
$(document).ready(function() {
  $('#trigger-modal-editor').click(function() {
    alert('Hello');
  });
</script>

This is not registering the art for some reason. Any help is appreciated!

1
  • That should work. You forgot to close $(document).ready(function() { ... }); though. If the elements are dynamically generated, use event delegation. Commented Jan 26, 2015 at 0:29

1 Answer 1

1

You're forgetting to close the ready handler:

$(document).ready(function() {
  $('#trigger-modal-editor').click(function() {
    alert('Hello');
  });
});//this 

Also, you don't have any text inside #trigger-modal-editor, place some text there to click in.

Sign up to request clarification or add additional context in comments.

3 Comments

Sorry, I forgot to add the closing brace and parenthesis to the post, but they are in my actual code. The span is creating a font awesome icon and I am wanting to trigger the click even when the icon is clicked. The class responsible for this is fa fa-cogs. Any other suggestions?
try $(document).on('click', '#trigger-modal-editor',function() {
This worked for me. Thank you very much! Is there a reason this worked and my code did not?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.