Web Development with jQuery®

(Elliott) #1

(^30) ❘ CHAPTER 2 SELECTING AND FILTERING


  • Wrox

  • Daring Fireball

  • Apple

  • jQuery

  • Example 2-2

  • Example 2-3




  • In the preceding markup document, you have a simple unordered list that contains six links. You
    take that markup and put it with the following CSS:
    body {
    font: 16px Helvetica, Arial, sans-serif;
    }
    ul {
    list-style: none;
    margin: 10px;
    padding: 10px;
    border: 1px solid green;
    }
    a {
    text-decoration: none;
    color: green;
    }
    a:hover {
    text-decoration: underline;
    }
    The preceding CSS document does little more than make that list look a little prettier—it neither
    adds to or takes away from the example.
    Finally, you add the following JavaScript document to the markup:
    $(document).ready(
    function()
    {
    $('a').click(
    function(event)
    {
    var node = $(this);
    var target = node.attr('target');
    var href = node.attr('href');
    if (target === undefined && href !== undefined)
    {
    switch (true)
    {
    case href.indexOf('http://') !== -1:
    case href.indexOf('https://') !== -1:
    case href.indexOf('.pdf') !== -1:
    {
    node.attr('target', '_blank')
    [http://www.it-ebooks.info](http://www.it-ebooks.info)
    Free download pdf