Solved

jquery onclick detect id value

Posted on 2014-01-23
2
241 Views
Last Modified: 2014-01-23
Hi, I am trying to for example alert a popup if and id has a value. so far the code does a popup with the id value and and blank popup if it has no value.  I want to make sure there is not popup if there is no id value.

 $(document).ready(function () {
         $("a").click(function () {
            
             if ($('a').val) {
                 alert(this.id);
             }
             else {
                 'nothing happen'
             }
           
     });
     });

 <a href="#" id="33" class="ui-link-inherit" >link1</a>

 <a href="#" id="34" class="ui-link-inherit" >link2</a>

 <a href="#"  class="ui-link-inherit" >link no id1</a>

 <a href="#"  class="ui-link-inherit" >link no id2</a>

Open in new window

0
Comment
Question by:sevensnake77
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39803369
http://jsfiddle.net/GaryC123/4KhMH/
$(document).ready(function () {
         $("a").click(function () {

             if ($(this).val && $(this).attr("id")) {
                 alert(this.id);
             }
             else {
                 'nothing happen'
             }
           
     });
     });

Open in new window

0
 
LVL 9

Author Closing Comment

by:sevensnake77
ID: 39803388
Great thanks
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now