In a php page I have placed a submit button,
HTML:
<input type="submit" name="btnAdd" id="btnAdd" Value="Add">
I need to hide this button (using jQuery) when link is cliked,
Link:
echo '<a href=" '.$_SERVER['PHP_SELF'].'" onClick="MyFunction()"> Edit </a>';
Javascript:
<script type="text/javascript">
$(document).ready(function() {
function MyFunction(){
$('btnAdd').hide();
});
</script>
But this code does not hide the button as expected. How can I fix this?
You have a wrong selector. You need to use
#btnAddfor an id selector:Also you should put the
MyFunctionfunction outside of thedocument.readycallback to avoid making it privately scoped.Another possibility is to do this unobtrusively:
which seems easier to be written as:
and then subscribe for the
.click()event of the edit link: