Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding element using its innerHTML

Please have a look to this DOM Tree...

  <div>

      <div>

            <span>  Home1  </span>

      </div>

      <span>  Home2  </span>

      <span>  Home3  </span>

  </div>

Now suppose I have a scenario where somehow I got the innerHTML of first span Home1. Is it possible to get the element span and its parent div by using only this (Home1) information.

like image 772
DEV Avatar asked Jan 30 '14 09:01

DEV


People also ask

How do I get the innerHTML element?

Setting the innerHTML property of an element To set the value of innerHTML property, you use this syntax: element. innerHTML = newHTML; The setting will replace the existing content of an element with the new content.

How use innerHTML with div tag?

To append using the innerHTML attribute, first select the element (div) where you want to append the code. Then, add the code enclosed as strings using the += operator on innerHTML.

How do you call a function in innerHTML?

To achieve this end, the code creates a document fragment object. As a result the code is able to add the LI elements as well as the id of each one and set the onclick event-property of each in a function invoked by the docs. forEach() .

Why is element innerHTML used?

The innerHTML property can be used to write the dynamic html on the html document. It is used mostly in the web pages to generate the dynamic html such as registration form, comment form, links etc.


1 Answers

Here is what you want.

Here is html:

<label>opal fruits</label>

Here is jQuery:

$("label:contains(opal fruits)")
like image 73
Zaheer Ahmed Avatar answered Sep 28 '22 12:09

Zaheer Ahmed