I have a submit button that has got a dynamically generated id. I want to make this button invisible once it was clicked once. At the same time another button which is invisible when the page loads will become visible instead.
But how can I reference the button I want to make invisible if the id is generated dynamically. I know the id always starts with the string 'product_'. Can I use left/subs开发者_开发知识库tring somehow to get control of this button? And how do I do it?
You could use the attribute starts with selector:
$("button[id^='product_']")
jQuery. You need to use live or delegate methods to access a dynamically generated ids
$('button[id^="product_"]').live('click', function(){alert("Hi");})
As an alternative you could give your two buttons unique css class names then you do not need to worry about the id's?
精彩评论