How to pass the value of each click to the anchor tag using jquery?


Harry Darkay

How to pass the value of each click to the anchor tag using jquery? I have this code here. I am trying to get the value every time I click the button

//My HTML
<button id="a-selectNm" data-a_name="<?php echo $row['username']; ?>"  data-toggle="modal" data-target="#selectNm">SELECT nursemaid</a>

//The modal
<div class="modal" id="selectNm">
<div class="card-body">
    <h4 class="card-title">
        <a href="#a_name"><?php echo $row['username']; ?></a>
    </h4>
</div>
</div>

//My jQuery code
jQuery(document).on('click', 'button#a-selectNm', function() {
    var a_name = jQuery(this).data('a_name');
    jQuery('.modal a[href="#a_name"]').val(a_name);
});
</script>

What's wrong with me, what do I need to change?

I think

replace

jQuery('.modal a[href="#a_name"]').val(a_name);

and

jQuery('.modal a[href="#a_name"]').text(a_name);

Related


Bind value to pass to on:click callback (anchor tag)

Ivan Quintero I'm building a sidebar component that updates the active link when one of the sidebar items is clicked. So I need to pass the current sidebar item object to enable its active state. Question: How to pass value to callback after on:click event? He

Bind value to pass to on:click callback (anchor tag)

Ivan Quintero I'm building a sidebar component that updates the active link when one of the sidebar items is clicked. So I need to pass the current sidebar item object to enable its active state. Question: How to pass value to callback after on:click event? He

Bind value to pass to on:click callback (anchor tag)

Ivan Quintero I'm building a sidebar component that updates the active link when one of the sidebar items is clicked. So I need to pass the current sidebar item object to enable its active state. Question: How to pass value to callback after on:click event? He

Bind value to pass to on:click callback (anchor tag)

Ivan Quintero I'm building a sidebar component that updates the active link when one of the sidebar items is clicked. So I need to pass the current sidebar item object to enable its active state. Question: How to pass value to callback after on:click event? He

How to change anchor tag's text on click using jquery?

Start I want to change the text of anchor tag on click event using jquery. Anchor Tag: <a id="view_email" href="#"><i class="fa fa-envelope"></i> View Email</a> query code: <script type="text/javascript"> $(document).ready(function(){ $("#view_email").cl

How to click anchor tag from javascript or jquery

151291 There is an anchor tag, try to click it from javascript, it doesn't respond, and when the page loads, it goes to next.phpwithout manually clicking the anchor tag . How to archive it? <!DOCTYPE html> <html> <head> <title></title> <script src="jqu

How to click anchor tag from javascript or jquery

151291 There is an anchor tag, try to click it from javascript, it doesn't respond, and when the page loads, it goes to next.phpwithout manually clicking the anchor tag . How to archive it? <!DOCTYPE html> <html> <head> <title></title> <script src="jqu

How to click anchor tag from javascript or jquery

151291 There is an anchor tag, try to click it from javascript, it doesn't respond, and when the page loads, it goes to next.phpwithout manually clicking the anchor tag . How to archive it? <!DOCTYPE html> <html> <head> <title></title> <script src="jqu

How to click anchor tag from javascript or jquery

151291 There is an anchor tag, try to click it from javascript, it doesn't respond, and when the page loads, it goes to next.phpwithout manually clicking the anchor tag . How to archive it? <!DOCTYPE html> <html> <head> <title></title> <script src="jqu

How to click anchor tag using Selenium WebDriver

Shubham Mishra: I can't click the button with some visibility issues. I need to hover over the link before clicking the same link. <a tabindex="0" class="cardPreviewLink expand-icon" aria-label="card opens in new tab" target="_blank" id="card-p

How to click anchor tag using Selenium WebDriver

Shubham Mishra: I can't click the button with some visibility issues. I need to hover over the link before clicking the same link. <a tabindex="0" class="cardPreviewLink expand-icon" aria-label="card opens in new tab" target="_blank" id="card-p

How to click anchor tag using Selenium WebDriver

Shubham Mishra: I can't click the button with some visibility issues. I need to hover over the link before clicking the same link. <a tabindex="0" class="cardPreviewLink expand-icon" aria-label="card opens in new tab" target="_blank" id="card-p

How to click anchor tag using Selenium WebDriver

Shubham Mishra: I can't click the button with some visibility issues. I need to hover over the link before clicking the same link. <a tabindex="0" class="cardPreviewLink expand-icon" aria-label="card opens in new tab" target="_blank" id="card-p

How to click anchor tag using Selenium WebDriver

Shubham Mishra: I can't click the button with some visibility issues. I need to hover over the link before clicking the same link. <a tabindex="0" class="cardPreviewLink expand-icon" aria-label="card opens in new tab" target="_blank" id="card-p

How to click anchor tag using Selenium WebDriver

Shubham Mishra: I can't click the button with some visibility issues. I need to hover over the link before clicking the same link. <a tabindex="0" class="cardPreviewLink expand-icon" aria-label="card opens in new tab" target="_blank" id="card-p

Unable to get anchor tag value using jquery

Muhammad Rabbi Ullah Rabbi I have a .outerdivmethod that dynamically adds html elements via script. Inside that div there is an anchor and i want to bind an event or access the inner text i tried using jquery but something is failing, please help. Here is the

Unable to get anchor tag value using jquery

Muhammad Rabbi Ullah Rabbi I have a .outerdivmethod that dynamically adds html elements via script. Inside that div there is an anchor and i want to bind an event or access the inner text i tried using jquery but something is failing, please help. Here is the

Need help using JQuery to prevent click on invisible anchor tag

Samuel Cole In each of my portfolio items, I have a div that overlaps the top with its opacity set to zero. When the user hovers over an item (or on mobile, clicks an item), the div transitions to opacity: 1. My problem is that if the user clicks any anchor ta

Need help using JQuery to prevent click on invisible anchor tag

Samuel Cole In each of my portfolio items, I have a div that overlaps the top with its opacity set to zero. When the user hovers over an item (or on mobile, clicks an item), the div transitions to opacity: 1. My problem is that if the user clicks on any of the