Site logo

Archived topic

Put jquery function in a hook but it does'nt work

4 replies · Started by Christian on November 28, 2017

Viewing posts 1–5 of 5

Hi folks,
im just setting up a new site for a real estate agent. On the single views of the objects there is an "object-id" which I want to transmit to a CF7 form. Therefore I've added a button in the single view which opens the site with the form. Additonally I've added a jquery function in the wp_footer area of the GP-Hooks. But this does'nt seems to work and I'm not a professional coder to get this solved. Is anyone here who might have an idea?

Please see here for details (single view):
https://www.auf-dem-land-wohnen.de/wordpress/immobilien/2017-05-barssel/

The orange button on the single view should "transfer" the object_id to the following form and fill it in the input area:
https://www.auf-dem-land-wohnen.de/wordpress/objektanfrage/

This is the code I used in the wp_footer hook area:

<script>
jQuery(function($){
let objNr = $('#eckdaten li span.objektnummer').html();
$('input[name="object_id"]').val(objNr);
})
</script>

The orange button is added with the shortcode ultimate plugin like this:
[su_button url="https://www.auf-dem-land-wohnen.de/wordpress/objektanfrage/" target="self" style="default" background="#ff9900" color="#FFFFFF" size="10" wide="no" center="no" radius="auto" class="pull-right right30"]Jetzt Anfrage stellen[/su_button]

Hi there,

I'm not seeing any orange button? Has it moved?

That code looks like it should store the HTML inside that span, and then update an input value with the stored HTML.

Maybe instead of .html(), try .text().

Hi Tom,

yes, actually I've removed it - just testing. :)
I will try it with .text() and activate the button again.

No, it's the same with .text()

Everything now is described as above right now.

Thanks for your help so far!

Regards,
Christian

Ah, well you need to give the button a class, then do something when the button is clicked:

jQuery( '.button-class' ).on( 'click', function( e ) {
    e.preventDefault();
    // Do stuff when the button is clicked.
} );
This archived topic is closed to new replies.