Solved

jquery onclick detect id value

Posted on 2014-01-23
2
245 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Converting dates in JavaScript 2 33
javascript: add id amounts 5 47
how can i test my code? 1 35
jQuery for Each 12 18
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
The viewer will learn how to count occurrences of each item in an array.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

776 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