Link to home
Start Free TrialLog in
Avatar of Yuri Boyz
Yuri BoyzFlag for Uganda

asked on

Hide buttons having dynamic id's on page loads

I have dynamically generated buttons which have ids like

 
id='modalButton-1'
id='modalButton-2'
id='modalButton-3'
id='modalButton-4'
id='modalButton-5'

Open in new window


The structure of button is as folows
<button class="abc"  data-target="dialog-message" value="0" id="modalButton-2">Add</button>

Open in new window


On page load I want to hide all the buttons which have id's as above or by using the data-target="dialog-message'  property.
There can be 2 buttons or 4 or 6 or whatever.

Need jQuery code help for this

Thanks
Avatar of Dorababu M
Dorababu M
Flag of India image

You can use the class instead of Id
$(".abc").hide()

Open in new window

Avatar of Yuri Boyz

ASKER

No I dont want to use class. It is used for some other purpose.
Ok may be can try this way

$('button').each(function() {
      //alert();
      if($(this).is(':contains("modalButton")'))
      {
      $(this).hide();
      }
      })

Open in new window

Sample fiddle for the above code https://jsfiddle.net/bnhuLdgf/3/
In your code you have not used id's:  id="modalButton-1",  id="modalButton-2",
Without these id this is useless for me.
How many Id's you have?
ASKER CERTIFIED SOLUTION
Avatar of Dorababu M
Dorababu M
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks,
you are welcome :)