Setting new value for an attribute using jQuery

前端 未结 2 2034
难免孤独
难免孤独 2020-12-01 10:03

I am trying to set a new vale of a custom attribute of a div using attr(). I found out it can be done using .attr( attributeName, value ), but when I try it it\

相关标签:
2条回答
  • 2020-12-01 10:40

    It is working you have to check attr after assigning value

    LiveDemo

    $('#amount').attr( 'datamin','1000');
    
    alert($('#amount').attr( 'datamin'));​
    
    0 讨论(0)
  • 2020-12-01 10:57

    Works fine for me

    See example here. http://jsfiddle.net/blowsie/c6VAy/

    Make sure your jquery is inside $(document).ready function or similar.

    Also you can improve your code by using jquery data

    $('#amount').data('min','1000');
    
    <div id="amount" data-min=""></div>
    

    Update,

    A working example of your full code (pretty much) here. http://jsfiddle.net/blowsie/c6VAy/3/

    0 讨论(0)
提交回复
热议问题