Home > Net >  click a button that I don't know the id
click a button that I don't know the id

Time:04-10

hello your help with a js code

I have the following structure

<span>
 <span>
  <input/>
 </span
 <button>
 </button>
</span

My question is how can I invoke the click on the button? I have tried the following code $("#938552dd-ed5a-4bea-833b-41f110a1c366").closest('wInput-date').children("button").trigger("click");

but I can't get it if you help please.

<span  data-id="cf018d18-c08c-477f-8a91-213944083232" data-val-id="938552dd-ed5a-4bea-833b-41f110a1c366" _bl_2d436386-enter code here7760-4ba0-9a8b-18c6033ed832="">
      <span  role="combobox" aria-expanded="false" aria-haspopup="true">
        <input  id="938552dd-ed5a-4bea-833b-41f110a1c366" tabindex="11" data-id="793b152c-d5e6-44b8-abef-fee3838ad1f5" type="text" _bl_cf0feb89-9608-41f7-a7d0-bcfab324c628="">
      </span>
      <button  id="8ec8f7d4-af4e-4340-9540-e424aa647b95" data-id="e0f6604d-8572-4aac-850d-d648a4c5ff37" tabindex="-1" aria-disabled="false" type="button">
      <span ></span>
      </button>
</span>

CodePudding user response:

. missed at the query selector of closest('.wInput-date')

here is the snippet after the edits

$( document ).ready(function() {
   $("#938552dd-ed5a-4bea-833b-41f110a1c366").closest('.wInput-date').children("button").trigger("click"); 
   //can also use .click() works like trigger 
});

to make sure that it really fired please add this block and check the console

$(".k-button").click(function(){
console.log("clicked");
});
  • Related