Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    100
    Rep Power
    0

    Change Text in links


    Code:
    $('a').click(function(){
    		$(this).html('Contact Us');
    		});
    Code:
    <a href="#">home</a>
    <a href="#">home</a>
    <a href="#">home</a>
    <button id="disable">Button</button>

    How i can change the text between 'a href' through Jquery?
    like on click the first one changes to Follow me 2nd to About us and 3rd to Contact us. How i can do it? i cant figure it out
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,663
    Rep Power
    1958
    Try have a look at the the nth-child-selector
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    100
    Rep Power
    0

    hmm


    let me use toggle function for it i think !
  6. #4
  7. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,663
    Rep Power
    1958
    Originally Posted by ionezation
    let me use toggle function for it i think !
    If this is the answer to your question, I don't think I actually understood what you asked about!
  8. #5
  9. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    what you're trying to do there makes no sense.

    It's great that you're having so much fun with JavaScript, but don't forget that user interfaces are actually meant to be usable by human beings. Things like references have a very specific meaning: They point to a certain resource. The content of the a element is the "label" telling the user what this resource is.

    That's how users expect links to work. When you break those basic expectations, you'll create a horrible user experience. No, I do not want to guess where the link points to. In fact, I don't even have JavaScript turned on. Does that mean I only see "home" links everywhere? Or does the website break altogether?
    The 6 worst sins of securityHow to (properly) access a MySQL database with PHP

    Why can’t I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    100
    Rep Power
    0
    what all i want is the text change replace when i click on first link then so on with others. like if the text is ['hello world'] so it converts to ['Word Hello'].

    Thats all i want on the click
  12. #7
  13. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,169
    Rep Power
    184
    Do you mean..., you want something like the code below?
    Code:
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script>
    $(document).on("ready",function(){
     $("a").click(function(event) {
       if($(this).attr("data-selector") != "visited"){
         $(this).html( $(this).html() + $(this).attr("data-selector") );
         $(this).attr("data-selector","visited");
       }
        event.preventDefault();
     });
    });
    </script>
    
    <a href="#" data-selector=" - You Have Visited This Page">Home</a><br/>
    <a href="#" data-selector=" - You Have Visited This Page">Page 1</a><br/>
    <a href="#" data-selector=" - You Have Visited This Page">Page 2</a>

    Comments on this post

    • Jacques1 disagrees : Your attitude of "F*ck you all, here's my solution" is starting to become a problem ...
    Last edited by web_loone08; December 29th, 2013 at 06:54 PM.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    100
    Rep Power
    0

    Thumbs up


    wow cool :P ... cant we change the whole text from the 'a' tag?

    you made this when clicked :
    Page 2 - You Have Visited This Page

    I want this :
    You Have Visited This Page

    Instead of,
    Page 2 - You Have Visited This Page
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    100
    Rep Power
    0

    cool


    One thing more i have to ask.

    $(document).on("ready",function(){
    // some code
    });

    Is this the new way to write this ?

    $(document).ready(function(){
    // some code
    });
  18. #10
  19. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    web_loone08's variant is wrong, as explained in the manual.

    The correct and bloat-free approach is

    javascript Code:
    $(function () {
     
    	// code goes here
     
    });

    Comments on this post

    • web_loone08 disagrees : I really do not care what you think; your problems are insignificant to me. So, you know where you can go. And... there is nothing wrong with my code; your just a punk that wants to cause problems.
    The 6 worst sins of securityHow to (properly) access a MySQL database with PHP

    Why can’t I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    100
    Rep Power
    0

    ?


    what is wrong with it?
  22. #12
  23. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,236
    Rep Power
    1469
    Originally Posted by Jacques1
    web_loone08's variant is wrong, as explained in the manual.

    The correct and bloat-free approach is

    javascript Code:
    $(function () {
     
    	// code goes here
     
    });
    There is also this approach for when you need the entire page to load before executing. This will cause a delay, but may be required if you are doing extensive DOM manipulation. It can also be used to delay processing for scripts that are not immediately required.
    javascript Code:
    $(window).load(function() {
     
            // code goes here
     
    });
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!
  24. #13
  25. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,236
    Rep Power
    1469
    Originally Posted by ionezation
    what is wrong with it?
    It's deprecated. It really is in the manual as Jacques posted. If you click the link you can read the explanation.

    Comments on this post

    • web_loone08 agrees : My variant of the ready using the .on() API may be deprecated;but it is still functional and accessible up to the current version of jQuery (v10.2). And... for the most part; I usually use the .ready() API anyway.
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!
  26. #14
  27. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Originally Posted by web_loone08
    So, you know where you
    can go. And... there is nothing wrong with my code; your just a punk that wants to cause problems.
    Two people have already pointed out your error. If you don't understand the manual, at least read the replies. Thanks.

    Apart from that: How old are you? 12?
    The 6 worst sins of securityHow to (properly) access a MySQL database with PHP

    Why can’t I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  28. #15
  29. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,169
    Rep Power
    184
    How old am I? Lol, that's a funny question coming from you; since your behavior is childish at best. It's just like a couple of days ago; when I was helping a OP and you just posted a stupid comment about the thread; that had absolutely nothing to do with the OP's question; just to be a jerk. You make childish comments like that all the time and you seem like you feel you can speak to people just however you feel. Well, guess what... you can't. As to the way I called the ready state; yes, it maybe depreciated, but as of the current version it is still accessible and functional, like in the example I provided the OP. As I indicated moments ago, I mostly use the .ready() API, the majority of the time anyway.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo