First you need to edit your searchform.php file. If you are using get_search_form(); read this . In case you use search widget you need to override the Widget.
If you dont want to use searchform.php you can go with filter:
function wpdocs_my_search_form( $form ) {
$form = '<form role="search" method="get" id="searchform" class="searchform" action="' . home_url( "https://wordpress.stackexchange.com/" ) . '" >
<div><label class="screen-reader-text" for="s">' . __( 'Search for:' ) . '</label>
<input type="text" value="' . get_search_query() . '" name="s" id="s" />
<input type="submit" id="searchsubmit" value="'. esc_attr__( 'Search' ) .'" />
</div>
</form>';
return $form;
}
add_filter( 'get_search_form', 'wpdocs_my_search_form' );
After that your wordpress search form should contain onclick=”openSearch()”. You can use Twenty twenty one theme as example. I have tested your code and its working. See screenshots – https://prnt.sc/1qloaxz https://prnt.sc/1qlof07
I would just go with JS or jQuery to target the overlay form.
JS
<script>
window.onload = function() {
var element = document.getElementsByClassName('target-class');
element.onclick = function() {
alert('Success');
}
}
</script>
jQuery
<script>
jQuery(document).ready(function() {
jQuery('.target-class').click(function() {
alert('Success');
});
});
</script>