user2015172
user2015172

Reputation: 57

Create link with JQuery

I got this Jquery code

  <head>
  <script type="text/javascript">
    $(document).ready(function() {
        $("#pav li a").click(function() {
            $(".srvctext").empty().append("<div id='loading'><img src='loading2.gif' alt='Loading' /></div>");
            $("#pav li a").css('color','#656565');
            $(this).css('color','#3ca5d4');
            $.ajax({ 
                url: this.href, 
                success: function(html) {
                    $(".srvctext").empty().append(html);
                }
            });
            return false;
        });


    });
</script>
  </head>

and this HTML

  <div class="srvclinksholder">
    <h4> Our Services </h4>

        <ul id="pav">
            <li><a href="pages/page_1.html"  id="mostPopular">Technical Infrastructure Service</a></li>
            <li><a href="pages/page_2.html"  id="mostPopular">Email Exchange Service (Messaging)</a></li>
            <li><a href="pages/page_3.html"  id="mostPopular">Firewall Services</a></li>
            <li><a href="pages/page_4.html"  id="mostPopular">Security and Antivirus Service</a></li>
....

I want to be able create a link from another page to one of these pages, I think I have to use # somehow just unsure. So if I have <a href="service/pages/page_4.html"> service being the page name that will not obviously work. Maybe something like this <a href="service.html#pages/page_4.html">

What changes do I have to make to achieve this?

Upvotes: 2

Views: 197

Answers (1)

abc123
abc123

Reputation: 18853

DEMO: http://jsfiddle.net/LxreN/3/

Basically you are going to be changing the html of the other div.

$(".srvctext").html("<div id='loading'><img src='loading2.gif' alt='Loading' /></div>");

with the following the in success, there isn't a need to empty everytime since that is causing 2 DOM accesses everytime, which IE doesn't handle well.

    success: function(html) {
        $(".srvctext").html(html);
    }

Upvotes: 1

Related Questions