0

I have this code that is a couple of links with divs inside them. When i click on one of the links it pops another div up that fills out using the "Case No" and "Type". However it only uses the data from the first link, not any other that i click.

HTML

<div class="plu-view-data">
 <a href="#" id="tp_0">
    <div class="tp-box">
        <div style="width: 45%; float:left;" id="type">TICKET</div><div style="width: 55%; float:left;">WRITTEN: 01/01/2018</div>
        <div id="case_no">CASE NO: 1234</div>
    </div>
 </a>
 <a href="#" id="tp_1">
    <div id="tp_id" class="tp-box">
        <div style="width: 45%; float:left;" id="type">WRITTEN WARNING</div><div style="width: 55%; float:left;">WRITTEN: 01/01/2018</div>
        <div id="case_no">CASE NO: 1235</div>
    </div>
 </a>
</div>

and the javascript is

$('.plu-view-data a').click(() => {
  $("#pedlookup-overlay").css('display','block')
  var type = $(this).find('#type').text()
  var caseno = $(this).find('#case_no').text()
  $('#plu-overlay-headbar').find('p').html(type+"  &nbsp;&nbsp; || &nbsp;&nbsp;  "+caseno)
})

Any idea as to why when i click the link it only uses the first link information?

3 Answers 3

2

The one tradeoff with using arrow functions is that there is no binding of this. To get it's context back you unfortunately have to go back to using the traditional function syntax (as it currently stands).

$('.plu-view-data a').click(function() {
  ...
});
Sign up to request clarification or add additional context in comments.

2 Comments

Thats what it was. Thanks for that. Ill mark as answer when it lets me.
Much appreciated. Glad I was able to help out.
0

You have duplicated id 'type' in your html. please change it.

Comments

0

$('.plu-view-data a').click(function() {
    $("#pedlookup-overlay").css('display', 'block')
    var type = $(this).find('#type').text();
    var caseno = $(this).find('#case_no').text();
    if (type && caseno) {
        console.log(caseno);
        $('#plu-overlay-headbar').find('p').html(type + "  &nbsp;&nbsp; || &nbsp;&nbsp;  " + caseno)
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="plu-view-data">
 <a href="#" id="tp_0">
    <div class="tp-box">
        <div style="width: 45%; float:left;" id="type">TICKET</div><div style="width: 55%; float:left;">WRITTEN: 01/01/2018</div>
        <div id="case_no">CASE NO: 1234</div>
    </div>
 </a>
 <a href="#" id="tp_1">
    <div id="tp_id" class="tp-box">
        <div style="width: 45%; float:left;" id="type">WRITTEN WARNING</div><div style="width: 55%; float:left;">WRITTEN: 01/01/2018</div>
        <div id="case_no">CASE NO: 1235</div>
    </div>
 </a>
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.