Morgan Ng Morgan Ng - 1 year ago 87
HTML Question

Passing text after onclick on href in jQUERY

I want to get the text from onclick href in particular href when class="bank cur" while getting the data-name="建设银行"

But it does not work. In function i am getting nothing to pass.Please help how to get value the text.

<ul class="bank_list">
<li class="bank_1" data-name="建设银行"><a href="javascript:void(0)" class="bank cur"></a></li>
<li class="bank_2" data-name="CHINA BANK"><a href="javascript:void(0)" class="bank "></a></li>
<li class="bank_3" data-name="OCBC BANK"><a href="javascript:void(0)" class="bank "></a></li>

and pass it to change the 选择银行 to 建设银行 :

<em name="bankName" id="bankNameList">选择银行</em>



$(".add_bankcard").click(function () {


$("#bankNameList").click(function () {


Answer Source

You are adding click events to the anchor, but all of the data attributes you want to read are on the li. So you need to use data() on the parent element.

    var name = $(this).parent("li").data("name");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download