Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 416
  • Last Modified:

jQuery: Select links that do not contain a period.

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
hankknight
Asked:
hankknight
2 Solutions
 
leakim971PluritechnicianCommented:
0
 
Ishaan RawatDesigner | Developer | ProgrammerCommented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now