How to add an HTML attribute with jQuery

后端 未结 7 744
无人及你
无人及你 2020-12-03 11:34

Well, I have this jQuery image slideshow that uses the attribute \"control\" inside an . Seeing how it didn\'t validate I searched for a way to add this attribute i

7条回答
  •  抹茶落季
    2020-12-03 11:38

    Let me see if I understood you. You have, for example, the code:

    
    

    And by jQuery you want it to be:

    
    

    Is it right? If it is. You just have to do:

    $('#previous').attr('control', -6);
    

    If an attribute doesn't exists it's created by jQuery. So, to remove it you can do:

    $('#previous').removeAttr('control');
    

    What you're doing doesn't respect the html rules and everything else, but it works fine, a lot of plugins do the same. ;D

    I hope this could be helpful!

    See you!

提交回复
热议问题