?
Solved

jquery onclick detect id value

Posted on 2014-01-23
2
Medium Priority
?
263 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:Seven price
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 2000 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:Seven price
ID: 39803388
Great thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
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 …
Suggested Courses

801 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