Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

jQuery: Select links that do not contain a period.

Posted on 2013-06-07
2
Medium Priority
?
406 Views
Last Modified: 2013-06-07
Using jQuery, how can I add a condition so that this is not matched if the link contains a period?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Demo</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready(function() {

    $('a[href]').each(function () {
        $(this).css('background','yellow');
    });

    $('a[href]').not('[href^="http"],[href^="mailto:"],[href^="/"],[href^="#"]').each(function () {
        $(this).css('background','red');
    });

});

</script>

</head>
<body>


<p>

<a href="#hello">Yellow</a>
<a href="world">Red</a>
<a href="mailto:email@example.com">Yellow</a>
<a href="/">Yellow</a>
<a href="test.html">Yellow</a>


</p>


</body>
</html>

Open in new window

0
Comment
Question by:hankknight
[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 82

Accepted Solution

by:
leakim971 earned 1600 total points
ID: 39229144
0
 
LVL 10

Assisted Solution

by:Ishaan Rawat
Ishaan Rawat earned 400 total points
ID: 39229155
Try this...

$("a[href*="."]").each(function() {
     // do as your wish with the a elements having . in their href...
});

Open in new window


or if you just want to add CSS... then you can do that by CSS to..

a[href*="."]{
     // do as your wish with the a elements having . in their href...
}

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
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 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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Suggested Courses

660 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