To interact with a dynamic div that is generated without any specific ID or class, which is contained within a fixed div, you can

Is there a way to trigger a click function using JQUERY on the div that includes the text "Save as JPEG"? The div with the ID "graph1" remains static while all other nested divs are dynamic. Please note that the dynamic div containing the text does not have any specific class or ID assigned.

<div id="graph1" class="col-sm-12" style="height: 250px">
    <div class="contianer">
        <div class="convascharttoolbar">
            <div>
                <div>save jpeg</div>
                <div>save png</div>
            </div>
        </div>
    </div>
</div>

Answer №1

Utilize the :contains(TEXT) selector to target all elements containing a specific text.

$("div:contains('search query')").on("click",function(){
  console.log(this.textContent);
});

Answer №2

Live Example

$(document).ready(function() {
  
  $("#graph1").on('click','div', function() {
    if($(this).text() == "save as jpeg"){
      alert('Div clicked')
    }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="graph1" class="col-sm-12" style="height: 250px">
  <div class="contianer">
    <div class="convascharttoolbar">
      <div>
        <div>save as jpeg</div>
        <div>save png</div>
      </div>
    </div>
  </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The second instance of a React Paginate on the same page remains static and does not trigger a

Having a bit of trouble with using react-paginate for pagination - I have two instances on the same page (one at the top and one at the bottom). When a new prop is received, only the top instance gets re-rendered. The code seems to be working fine as all ...

Import objects into THREE.js using OBJLoader, convert to Geometry, apply transformations, and finally convert to BufferGeometry

Trying to figure out why the geometry loaded with OBJLoader cannot be smoothly shaded. var loader = new THREE.OBJLoader(manager); loader.load('/manmodel/js/man.obj', function (object, materials) { console.log(object); console.log(materia ...

Disable the add to cart popup in Prestashop while keeping the ajax add to cart functionality active

Is there a way to turn off the popup that appears when adding a product to the cart using ajax? I've been looking through ajax-cart.js but couldn't find anything related to the popup. I don't want to completely disable the ajax add to cart f ...

There are two images within a container - one as the background and the other as the foreground. What measures can I take to

I am experiencing an issue with two images on my website. One is set as the background and the other is displayed above it, appearing properly when viewed on larger screens but distorting when the browser window is minimized. You can view the site at the f ...

Is it possible to use font-face in CSS3 to switch fonts for different languages?

Can I replace an Arabic font with a custom one using font-face in CSS3? I've successfully done it with English but I'm not sure if it's the same for foreign languages, so I wanted to check. Also, I feel silly asking this question, but I&apos ...

Tips for identifying the version of a package that is installed using a package-lock.json file containing lockfileVersion = 3

After upgrading from Node 16 (npm 8) to Node 18 (npm 9), I noticed a difference in the structure of the package-lock.json files. Files generated with npm 8 have a lockfileVersion: 2, while those generated with npm 9 have a lockfileVersion: 3. The changes a ...

Showing SQL query results on a Leaflet map

I am facing an issue with my leaflet map. I am trying to display an SQL query but it is not working as expected. I have stored the result in a JS variable as follows: <?php $connect = connect(); $req_ch = "SELECT json_build_object( 'type&apo ...

How can I adjust a centered container div to fit properly on a mobile device

Exploring the centering of a particular div: #container { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); height: 550px; width: auto; background: rgba(28, 28, 54, 0.70); padding: 15px; border: 1px solid #1c ...

a handy jquery tool that smoothly glides a div element across the screen from one end to the other

I am looking to create a div that will scroll from one side of the window to the opposite side, containing an image inside it. Here is the code I have tried so far: $('#fly').animate({left: $(window).width()+'px'}, 2000, 'linear& ...

Display a JSON object on a web browser

I am trying to display a JSON object on a web browser using HTML. The object is already in a text file and has been properly formatted for readability. My goal is to maintain the same formatting when displaying it on the browser. ...

Retrieving radio button values in React from a different component

I am dealing with a child component that contains radio buttons, each with its own value. I have imported this child component into a parent component to manage its state from the parent component. With the child component added, I need to access all the i ...

The focusable attribute in SVG is malfunctioning

I've utilized the focusable attribute to ensure SVG elements receive focus within an HTML document. My goal is to navigate through SVG elements in the SVG tag using the TAB key, as indicated in this resource (http://www.w3.org/TR/SVGTiny12/interact.h ...

Server side progress bar with Jquery

I am currently dealing with a lengthy server-side process that is not fixed in terms of time and involves running multiple queries in the database. This process takes more than 30 seconds to complete. I am looking for a way to show the progress in percen ...

Is it feasible to navigate through submenus using only the [Tab] key in CSS?

Is there a way to activate a submenu in a styled menu using only the [Tab] key so that the submenu becomes visible? I attempted to use the :focus pseudo-class ul li a:focus + ul li a ... and when t ...

The Eclipse Phonegap framework is experiencing difficulty in loading an external string file with the jquery .load function

A basic index.html file has been created to showcase a text string from the test.txt file by utilizing the .load function from the jQuery library. The goal is to insert the textual content into an HTML (div class="konten"). The provided HTML script looks ...

State loss occurs when moving to a different page using next/link

Currently, I am working on a library application with Next.js. Within this project, there are two main pages: BooksPage, which displays a list of all books, and BookPage, where detailed information about a specific book is shown. The components involved in ...

The issue of empty data in Symfony 3 Form Ajax Post Requests

Displaying a list of tags with the option to add more dynamically. Using Ajax instead of Symfony Doctrine for form submission to allow dynamic updates without page reloads. This is how the form is structured in HTML: <div class="tag-form" ...

Is it possible to use JavaScript to save and preserve the current state of a webpage?

I'm looking for a way to retrieve the entire content of a webpage using JavaScript and then send it to a server script for saving. This action should be triggered after the user has made some changes to the page using AJAX and other JavaScript tools. ...

Is it a scope issue if ng-click is not firing and the function is not working properly?

I'm facing an issue with an animation that is not working as intended. The goal is to have the search button trigger an animation to pull a search bar from the right side, allowing users to input their search query. However, the ng-click function does ...

Animating back with a jQuery if statement

Is there a way to implement an if statement that triggers an animation when the right image reaches +400px, and then animates back to -400px upon hovering over the image? $('#left img').mouseenter(function() { $('#right img').animate ...