Can't Target a Widget's Elements using jQuery

I have a sidebar widget that has some elements inside I'd like to modify. The widget generates it's code from

I have a sidebar widget that has some elements inside I'd like to modify. The widget generates it's code from the "Action Network", so the content of the widget is loaded dynamically from another site which renders the markup.

<div id="can-petition-area-build-more-social-housing" style="width: 100%">  <div class="can_embed v3  petition">
    <div id="can_embed_form">
          <div id="can_embed_form_inner">

When I am in Chrome, I can target the elements easily, for instance:

jQuery('#can_embed_form').hide();

Hide the DIV. However, when I run the same code from a jQuery file, nothing happens and I get no errors at all. Am enqueuing the script file in the wp_enqueue_scripts action (it spits out code when I type include console.log('xyz') so it's properly loaded.

This is my JS file:

jQuery(document).ready(function($){
    $('#can_embed_form_inner').hide();
});

If I hide something that is not part of the widget from within the JS file, it does hide it, which makes me think the widget is not in the DOM when jQuery is trying to get the div by element.

I would've thought the ready() function would take care of that but am clearly wrong.

Any pointers would be greatly appreciated!

Thanks!

I have a sidebar widget that has some elements inside I'd like to modify. The widget generates it's code from the "Action Network", so the content of the widget is loaded dynamically from another site which renders the markup.

<div id="can-petition-area-build-more-social-housing" style="width: 100%">  <div class="can_embed v3  petition">
    <div id="can_embed_form">
          <div id="can_embed_form_inner">

When I am in Chrome, I can target the elements easily, for instance:

jQuery('#can_embed_form').hide();

Hide the DIV. However, when I run the same code from a jQuery file, nothing happens and I get no errors at all. Am enqueuing the script file in the wp_enqueue_scripts action (it spits out code when I type include console.log('xyz') so it's properly loaded.

This is my JS file:

jQuery(document).ready(function($){
    $('#can_embed_form_inner').hide();
});

If I hide something that is not part of the widget from within the JS file, it does hide it, which makes me think the widget is not in the DOM when jQuery is trying to get the div by element.

I would've thought the ready() function would take care of that but am clearly wrong.

Any pointers would be greatly appreciated!

Thanks!

Share Improve this question edited Aug 30, 2019 at 4:02 csaborio asked Aug 30, 2019 at 3:55 csaboriocsaborio 1122 silver badges13 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Man, every time all it takes is to press that post button and then I find the answer seconds later - lol:

jQuery(document).ready(function($){
    $(document).ready(function() {
        $(document).on('can_embed_loaded', function() {
            // do your work here, after the widget is loaded
            $('input[name="commit"]').val('Sign My Awesome Petition');
        });
    }); 
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745200138a4616283.html

相关推荐

  • Can&#39;t Target a Widget&#39;s Elements using jQuery

    I have a sidebar widget that has some elements inside I'd like to modify. The widget generates it's code from

    5小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信