JavaScript Find li element by inner text of inside span find inner element jquery,find inner element javascript,find inner

I have HTML like below

<ul id="tabStripSecondaryElements" class="k-tabstrip-items k-reset" data-role="tabstrip" style="margin-left: 37px; margin-right: 40px;" role="tablist" aria-activedescendant="tab_0">
   <li class="k-item tabClick k-state-default k-first" id="tab_1" value="1" role="tab" aria-controls="tabStripSecondaryElements-1"><span class="k-loading k-complete"></span><span unselectable="on" class="k-link"> Automobile&nbsp;&nbsp;&nbsp;<span class="fa fa-ellipsis-v"></span></span></li>
   <li class="k-item tabClick k-state-default" id="tab_3" value="3" role="tab" aria-controls="tabStripSecondaryElements-2"><span class="k-loading k-complete"></span><span unselectable="on" class="k-link"> Router&nbsp;&nbsp;&nbsp;<span class="fa fa-ellipsis-v"></span></span></li>
   <li class="k-item tabClick k-state-default" id="tab_4" value="4" role="tab" aria-controls="tabStripSecondaryElements-3"><span class="k-loading k-complete"></span><span unselectable="on" class="k-link"> Smart City Sensor&nbsp;&nbsp;&nbsp;<span class="fa fa-ellipsis-v"></span></span></li>
   <li class="k-item tabClick k-state-default" id="tab_5" value="5" role="tab" aria-controls="tabStripSecondaryElements-4"><span class="k-loading k-complete"></span><span unselectable="on" class="k-link"> ZigBee Power Cable&nbsp;&nbsp;&nbsp;<span class="fa fa-ellipsis-v"></span></span></li>
   <li class="k-item tabClick k-state-default" id="tab_6" value="6" role="tab" aria-controls="tabStripSecondaryElements-5"><span class="k-loading k-complete"></span><span unselectable="on" class="k-link"> Tracker&nbsp;&nbsp;&nbsp;<span class="fa fa-ellipsis-v"></span></span></li>
   <li class="k-item tabClick k-state-default" id="tab_7" value="7" role="tab" aria-controls="tabStripSecondaryElements-6"><span class="k-loading k-complete"></span><span unselectable="on" class="k-link"> Fleet Intelligence&nbsp;&nbsp;&nbsp;<span class="fa fa-ellipsis-v"></span></span></li>
   <li class="k-item tabClick k-state-default" id="tab_8" value="8" role="tab" aria-controls="tabStripSecondaryElements-7"><span class="k-loading k-complete"></span><span unselectable="on" class="k-link"> Mobile&nbsp;&nbsp;&nbsp;<span class="fa fa-ellipsis-v"></span></span></li>
   <li class="k-item tabClick k-state-default" id="tab_9" value="9" role="tab" aria-controls="tabStripSecondaryElements-8"><span class="k-loading k-complete"></span><span unselectable="on" class="k-link"> Double Door&nbsp;&nbsp;&nbsp;<span class="fa fa-ellipsis-v"></span></span></li>
   <li class="k-item tabClick k-state-default" id="tab_87" value="87" role="tab" aria-controls="tabStripSecondaryElements-10"><span class="k-loading k-complete"></span><span unselectable="on" class="k-link"> Test&nbsp;&nbsp;&nbsp;<span class="fa fa-ellipsis-v"></span></span></li>

</ul>

I am trying to find the li element by the inner text of inside span element.

Eg: Router has the li element id - tab_1

I tried using following jquery code but it's not working and returning empty

$('li.k-item tabClick k-state-default span.k-link:contains("Router")');

Is there any other way to get this?

Answer:1

The issue is with your selector. You have spaces between the k-item tabClick k-state-default classes, where they should be joined together with period delimiters for the class selector prefix. This will then select the span. To get the li from this you can use closest():

var $span = $('li.k-item.tabClick.k-state-default span.k-link:contains("Router")');

var $li = $span.closest('li');
$li.css('color', '#C00');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul id="tabStripSecondaryElements" class="k-tabstrip-items k-reset" data-role="tabstrip" style="margin-left: 37px; margin-right: 40px;" role="tablist" aria-activedescendant="tab_0">
  <li class="k-item tabClick k-state-default k-first" id="tab_1" value="1" role="tab" aria-controls="tabStripSecondaryElements-1">
    <span class="k-loading k-complete"></span>
    <span unselectable="on" class="k-link"> 
      Automobile&nbsp;&nbsp;&nbsp;
      <span class="fa fa-ellipsis-v"></span>
    </span>
  </li>
  <li class="k-item tabClick k-state-default" id="tab_3" value="3" role="tab" aria-controls="tabStripSecondaryElements-2">
    <span class="k-loading k-complete"></span>
    <span unselectable="on" class="k-link"> 
      Router&nbsp;&nbsp;&nbsp;
      <span class="fa fa-ellipsis-v"></span>
    </span>
  </li>
  <li class="k-item tabClick k-state-default" id="tab_4" value="4" role="tab" aria-controls="tabStripSecondaryElements-3">
    <span class="k-loading k-complete"></span>
    <span unselectable="on" class="k-link"> 
      Smart City Sensor&nbsp;&nbsp;&nbsp;
      <span class="fa fa-ellipsis-v"></span>
    </span>
  </li>
  <li class="k-item tabClick k-state-default" id="tab_5" value="5" role="tab" aria-controls="tabStripSecondaryElements-4">
    <span class="k-loading k-complete"></span>
    <span unselectable="on" class="k-link"> 
      ZigBee Power Cable&nbsp;&nbsp;&nbsp;
      <span class="fa fa-ellipsis-v"></span>
    </span>
  </li>
  <li class="k-item tabClick k-state-default" id="tab_6" value="6" role="tab" aria-controls="tabStripSecondaryElements-5">
    <span class="k-loading k-complete"></span>
    <span unselectable="on" class="k-link"> 
      Tracker&nbsp;&nbsp;&nbsp;
      <span class="fa fa-ellipsis-v"></span>
    </span>
  </li>
  <li class="k-item tabClick k-state-default" id="tab_7" value="7" role="tab" aria-controls="tabStripSecondaryElements-6">
    <span class="k-loading k-complete"></span>
    <span unselectable="on" class="k-link"> 
      Fleet Intelligence&nbsp;&nbsp;&nbsp;
      <span class="fa fa-ellipsis-v"></span>
    </span>
  </li>
  <li class="k-item tabClick k-state-default" id="tab_8" value="8" role="tab" aria-controls="tabStripSecondaryElements-7">
    <span class="k-loading k-complete"></span>
    <span unselectable="on" class="k-link"> 
      Mobile&nbsp;&nbsp;&nbsp;
      <span class="fa fa-ellipsis-v"></span>
    </span>
  </li>
  <li class="k-item tabClick k-state-default" id="tab_9" value="9" role="tab" aria-controls="tabStripSecondaryElements-8">
    <span class="k-loading k-complete"></span>
    <span unselectable="on" class="k-link"> 
      Double Door&nbsp;&nbsp;&nbsp;
      <span class="fa fa-ellipsis-v"></span>
    </span>
  </li>
  <li class="k-item tabClick k-state-default" id="tab_87" value="87" role="tab" aria-controls="tabStripSecondaryElements-10">
    <span class="k-loading k-complete"></span>
    <span unselectable="on" class="k-link"> 
      Test&nbsp;&nbsp;&nbsp;
      <span class="fa fa-ellipsis-v"></span>
    </span>
  </li>

</ul>
Answer:2

I have the following array: const x = [ {event: "oninput", action: ""}, {event: "onfocus", action: ""} ] Following is the desired output: // event: action { oninput: "", onfocus: "" ...

I have the following array: const x = [ {event: "oninput", action: ""}, {event: "onfocus", action: ""} ] Following is the desired output: // event: action { oninput: "", onfocus: "" ...

  1. convert array object to string
  2. convert array object to array javascript
  3. convert array object to string powershell
  4. convert array object to string javascript
  5. convert array object to list java
  6. convert array object to json
  7. convert array object to array php
  8. convert array object to list
  9. convert array object to list c#
  10. convert array object to string python
  11. convert array object to string c#
  12. convert array object to string php
  13. convert array object to object
  14. convert array object to list python
  15. convert array object to json php
  16. convert array object to object typescript
  17. convert array object to string jquery
  18. convert array object to json jquery
  19. convert array object to array python
  20. convert array object to json in javascript

I'm currently teaching myself functional programming. I'm trying to translate the following: (define a 3) (define b (+ a 1)) (* (cond ((> a b) a) ((< a b) b) (else -1)) (+...

I'm currently teaching myself functional programming. I'm trying to translate the following: (define a 3) (define b (+ a 1)) (* (cond ((> a b) a) ((< a b) b) (else -1)) (+...

  1. translate code from one language to another
  2. translate code from java to python
  3. translate code from matlab to python
  4. translate code from r to python
  5. translate code from welsh to english
  6. translate code from python to c++
  7. translate code from sas to r
  8. translate code from java to c#
  9. translate code from spanish to english
  10. translate code from vb.net to c#
  11. translate code from matlab to r
  12. translate code from matlab to julia
  13. translate code from chinese to english
  14. translate from code to english
  15. translate from code
  16. translate code of conduct
  17. translate code for website
  18. translate code in javascript
  19. translate code in python
  20. translate code in php

Using AirBnB's enzyme, we can setState of a component: const loginComponent = shallow(<Login />); loginComponent.setState({ error: true }); I want to do same thing using react-testing-library. ...

Using AirBnB's enzyme, we can setState of a component: const loginComponent = shallow(<Login />); loginComponent.setState({ error: true }); I want to do same thing using react-testing-library. ...

  1. component definition
  2. component to hdmi
  3. component synonym
  4. component form
  5. components of blood
  6. component cable
  7. componentdidupdate
  8. components of fitness
  9. component to hdmi converter
  10. component form of a vector
  11. components of a nucleotide
  12. components of gdp
  13. components of dna
  14. components of physical fitness
  15. component pouch 5e
  16. component speakers
  17. component video
  18. component hardware
  19. components of culture
  20. components of a business plan

I'm using ASP.net 4.5. I have a method like this: protected void OnConfirm(object sender, EventArgs e) { // this function checks if an id exist in database CheckIDExist(123); ...

I'm using ASP.net 4.5. I have a method like this: protected void OnConfirm(object sender, EventArgs e) { // this function checks if an id exist in database CheckIDExist(123); ...

  1. scriptmanager run script after postback
  2. asp.net run script after postback