Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    •  
      CommentAuthorAen
    • CommentTimeOct 10th 2008
     permalink
    <script type="text/javascript">
    $(document).ready(function() {
    $(".foo").click(function(){
    var $el = $(this);
    $el.replaceWith('<a href="/url?phpMyAdmin=4594f30712f4fabaff6997416810f3f2" rel="xyz" class="foo">Link</a>');
    return false;
    });
    });
    </script>
    <a href="/url?phpMyAdmin=4594f30712f4fabaff6997416810f3f2" rel="xyz" class="foo">Link</a>

    I should be able to keep clicking forever right? But it seems that after replaceWidth() for the <a> element, though having class="foo", return false; isn't working.

    Any jquery experts here can give me a hand?
    •  
      CommentAuthorAen
    • CommentTimeOct 10th 2008
     permalink
    No wait my example wasn't right.

    Try making this work.

    <script type="text/javascript">
    $(document).ready(function() {
    $(".foo").click(function()
    {
    var $el = $(this);
    $el.attr('href','/foo');
    $el.text('Bar');
    $el.removeClass('foo');
    $el.addClass('bar');
    return false;
    });
    $(".bar").click(function()
    {
    var $el = $(this);
    $el.attr('href','/bar');
    $el.text('Foo');
    $el.removeClass('bar');
    $el.addClass('foo');
    return false;
    });
    });
    </script>
    <a href="/url?phpMyAdmin=4594f30712f4fabaff6997416810f3f2" rel="xyz" class="foo">Link</a>


    The link should toggle between foo and bar but the generated <a class="bar"> doesn't react to the 2nd function.
  1.  permalink
    The issue is that the two functions are added when the page loads, at which point there are no links with the class=bar.

    To solve this you need to rewrite the script so that the function that is added not only changes the class but also the function that is attached.
Add your comments
    Username Password
  • Format comments as (Help)