Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2006
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    jquery question function

    I am using a script to change content in a window. I need the html contnet in window to be up by default. With this it's only up when you click link. What do I need to add to this?

    <script type="text/javascript">
    $(document).ready(function() {

    $('#links a').click(function() {
    var url=$(this).attr('href');
    $('#headlines').load(url + ' #newsItems');
    return false;
    });
    });
    </script>

  • #2
    Regular Coder
    Join Date
    Mar 2009
    Location
    Portland Oregon
    Posts
    690
    Thanks
    44
    Thanked 63 Times in 62 Posts
    there has to be a way to set the variable beforehand. Where's the script? Find out what names are used, find out the one you want for default, set it to that one to begin with, and you're done.

  • #3
    Regular Coder
    Join Date
    Feb 2009
    Location
    Wheeling, IL
    Posts
    358
    Thanks
    5
    Thanked 62 Times in 60 Posts
    Or just add one line like this:

    Code:
    <script type="text/javascript">
        $(document).ready(function() {
            $('#links a').click(function() {
                var url=$(this).attr('href');
                $('#headlines').load(url + ' #newsItems');
                return false;
            });
            $('#links a').click();
        });
    </script>
    Essentially triggers the click event on the link in question. It can be changed otherwise too... like so:

    Code:
    <script type="text/javascript">
        $(document).ready(function() {
            var url=$('#links a').attr('href');
            $('#headlines').load(url + ' #newsItems');
        });
    </script>
    But what you use is really up to you. The second one will have no effect if people actually do decide to click on the link, and it will follow the link, so the first solution might be the better choice, depending on what you really want to do.
    The way to success is to assume that there are no impossible things. After all, if you think something is impossible, you will not even try to do it.

    How to ask smart questions?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •