Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

jquery onclick detect id value

Posted on 2014-01-23
2
Medium Priority
?
279 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to implement server side field validation and display customized error messages to the client.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

610 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