The ATTR () method sets or returns the attribute value of the selected element. The working method varies according to different parameters of this method. Returns the attribute value of the selected element.
Page code:
HTML:
<Form action = "xxxxxx" method = "Post" id = "buy_form">
<Input type = "hidden" id = "paymethod" name = "paymethod" value = "directpay">
<Ul class = "NCC-payment-list">
<Li payment_code = "allstarpay" paymethod = "directpay"> ccccccc </LI>
</Ul>
</Form>
JS:
<SCRIPT type = "text/JavaScript">
$ (Function (){
$ ('. NCC-payment-List> li'). On ('click', function (){
$ ('# Paymethod'). Val ($ (this). ATTR ('paymethod '));
});
});
</SCRIPT>
After clicking the Li option on the page, directpay will assign the value of the Li label property paymethod to the input label with ID as paymethod.
Simple application example of the ATTR () method