JavaScript How to find parent closest anchor tag find closest parent jquery,find closest parent with class jquery,

Use .closest() (jQuery docs link)

$(this).closest('a');

From the API docs:

For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.

Answer:1

use .parent() then .prev methods $("#assignButton_NAGM15GRA4_HWK4OAC1").parent().prev().css({"color": "red", "border": "2px solid red"});

$("#assignButton_NAGM15GRA4_HWK4OAC1").parent().prev().css({"color": "red", "border": "2px solid red"});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li class="fa-2x lesson_strand active">
  <a onclick="window.open('/wwtb/api/viewer.pl?uid=demo_user&cid=1&wid=NAGM15GRA4_HWK4OAC1&role=Student','_blank','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=1014,height:655,left=150,top=50,titlebar=yes')" target='_blank' href="#">
    <b class="fa_text">Domain 4.OA Cluster 1 Quiz (Homework)</b>
  </a>
  <a onclick="window.open('/ePC/ePlannerAssessment.do?isbn=9780544349179&isSoar=0&toolType=12&uniqueID=NAGM15GRA4_HWK4OAC1&resourceBUID=NAGM15GRA4_HWK4OAC1&nextGenTool=WB%20HTTP/1.1','_blank','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=1014,height:655,left=150,top=50,titlebar=yes')"
  target='_blank' href="#">
    <span id="assignButton_NAGM15GRA4_HWK4OAC1" class="assignButton" onclick="assignclicksToButton(event)">Assign</span>
  </a>
</li>
Answer:2

Take closest li and then find the first a of this li. Hope the code snippet given below will help you.

$('#assignButton_NAGM15GRA4_HWK4OAC1').closest('li')
.find('a:first').css('background-color', 'green');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li class="fa-2x lesson_strand active">
    <a onclick="window.open('/wwtb/api/viewer.pl?uid=demo_user&cid=1&wid=NAGM15GRA4_HWK4OAC1&role=Student','_blank','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=1014,height:655,left=150,top=50,titlebar=yes')" target='_blank' href="#">
        <b class="fa_text">Domain 4.OA Cluster 1 Quiz (Homework)</b>
    </a>
    <a onclick="window.open('/ePC/ePlannerAssessment.do?isbn=9780544349179&isSoar=0&toolType=12&uniqueID=NAGM15GRA4_HWK4OAC1&resourceBUID=NAGM15GRA4_HWK4OAC1&nextGenTool=WB%20HTTP/1.1','_blank','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=1014,height:655,left=150,top=50,titlebar=yes')"
       target='_blank' href="#">
        <span id="assignButton_NAGM15GRA4_HWK4OAC1" class="assignButton" onclick="assignclicksToButton(event)">Assign</span>
    </a>
</li>
Answer:3

In my company want to modify one ASp.net Project, <% if(Request.QueryString["cert"]!=null) { %> <asp:TemplateField HeaderText="H&A" ItemStyle-Width="70px"> ...

In my company want to modify one ASp.net Project, <% if(Request.QueryString["cert"]!=null) { %> <asp:TemplateField HeaderText="H&A" ItemStyle-Width="70px"> ...

I am unable to find/pinpoint the root cause of the error. In my javascript file I keep getting a green squiggly under the the word angular. I don't understand why. (Im using Visual Studio Code) ...

I am unable to find/pinpoint the root cause of the error. In my javascript file I keep getting a green squiggly under the the word angular. I don't understand why. (Im using Visual Studio Code) ...

  1. angular error injector modulerr
  2. angular error injector unpr
  3. angular error injector nomod
  4. angular error injector
  5. angular injector error unknown provider
  6. angular uncaught error injector modulerr
  7. angular static injector error
  8. angular null injector error
  9. angular static injector error no provider
  10. angular static injector error httpclient
  11. angular static injector error appmodule
  12. angular debug injector error
  13. angular static injector error no provider for http
  14. angular static injector error http
  15. angularjs injector error
  16. angular service injector error
  17. angular filter injector error
  18. angular module injector error
  19. angular static injector error no provider for t
  20. angular material injector error

Sorry for silly question but I am new to AngularJS. I have a service which will fetch data to HTML page (login.html) in AngularJS. I have login.html page which will have this data when loading. In ...

Sorry for silly question but I am new to AngularJS. I have a service which will fetch data to HTML page (login.html) in AngularJS. I have login.html page which will have this data when loading. In ...

I am trying to add a span after dynamically generated table, but the span is getting added before the contents of table are getting loaded. Below is my code: <!DOCTYPE html> <html> <...

I am trying to add a span after dynamically generated table, but the span is getting added before the contents of table are getting loaded. Below is my code: <!DOCTYPE html> <html> <...

  1. insert span in input
  2. insert span in h1 jquery
  3. insert span in html
  4. insert in span jquery