Black Friday Sale! Get up to $40 off GP Premium!Learn more

[Support request] Put jquery function in a hook but it does'nt work

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

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #436773
    Christian

    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]

    GeneratePress 1.4
    GP Premium 1.5.5
    #437077
    Tom
    Lead Developer
    Lead Developer

    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().

    #437083
    Christian

    Hi Tom,

    yes, actually I’ve removed it – just testing. 🙂
    I will try it with .text() and activate the button again.

    #437088
    Christian

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

    Everything now is described as above right now.

    Thanks for your help so far!

    Regards,
    Christian

    #437301
    Tom
    Lead Developer
    Lead Developer

    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.
    } );
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.