Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8209713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:49:22+00:00 2026-06-07T09:49:22+00:00

In the following code: $(document).ready( function () { var hideInit = function () {

  • 0

In the following code:

$(document).ready( function () {
    var hideInit = function () {
            $(selector1).hide();
    }
    var loadInit = function () {
            //get data
            var thingo = $('<div />');
            //populate thingo with a bunch of divs matching selector1
            $(selector2).append(thingo);
    }
    loadInit();
    hideInit();
});

I am parsing some data and populating the DOM with it in loadInit, and then I wish to .hide each of the elements present in the DOM that was just created which match selector1.

Unfortunately the elements are not being hidden – what have I done wrong here?

Thanks!


Solution

My selectors weren’t incorrect, as suggested by many, but it was the order in which I was calling the functions. In order to guarantee that hideInit runs after loadInit has complete, I call it at the end, inside, of loadInit.

$(document).ready( function () {
    var hideInit = function () {
            $(selector1).hide();
    }
    var loadInit = function () {
            //get data
            var thingo = $('<div />');
            //populate thingo with a bunch of divs matching selector1
            $(selector2).append(thingo);
            hideInit();
    }
    loadInit();
});

Thanks for your comments/ answers!


NOT related to : Using jQUery hide() on newly created dom elements

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:49:23+00:00Added an answer on June 7, 2026 at 9:49 am

    This can be achieved with a single line that manipulates the DOM using the append, filter and hide jQuery methods.

    1. $('selector2').append(thingo) – append the items
    2. .filter('selector1') – of the original selector, only select those matching the filter
    3. .hide() – hide the filtered items

    Like this:

    $(function()
    {
        var thingo = $('<div />');
        $('selector2').append(thingo).filter('selector1').hide();
    }
    

    Optionally, if you want to hide the appended items, you’ll want to add an additional chain after the filter, whereby you could use the find() method, like this:

    // this will hide all child divs, so you may want to be more specific
    $('selector2').append(thingo).filter('selector1').find('div').hide();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having problems with the following code $(document).ready(function() { var $selection = $('<div
Can I get some help with the following code? $(document).ready(function() { $('#searchform').submit(function() { var
Div box dimensions are measured using jQuery with following code: $(document).ready(function(){ var h =
I have the following code: $(document).ready(function() { var ul = $(<div>); ul.addClass(menu).appendTo('.menuwrapper'); }); function
I have the following code: $(document).ready(function () { $('div.env').each(function (index, item) { var vm
I have the following code: $(document).ready(function() { var id = 'cbx'; var idPrefix =
I have the following JQuery code: $(document).ready(function () { var $containerHeight = $(window).height(); if
Consider the following code: $(document).ready(function() { $(body).append(<div class='outer'><span class='inner'>Click me</span></div>); $(html).click(function(event) { var targetClass
i can reference link with specific id with following code $(document).ready(function(){ $(a#example_link_id).click(function(event){ var url
I'm using the following code.. $(document).ready(function(){ $(#test a).click(function(){ var labelTo = $(this).text(); window.location =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.