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 768333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:09:56+00:00 2026-05-14T18:09:56+00:00

I have a div on a page whose contents is replaced by an AJAX

  • 0

I have a div on a page whose contents is replaced by an AJAX request when the user selects an option from a select list. When the page loads, I issue a command to disable the autocomplete feature for all of the pages text input elements:

//Stop that pesky browser autocomplete
$('input[type=text]').attr("autocomplete", "off");

However, when new elements appear in the div after an AJAX call, this line of code does not reference them because they were not part of the original DOM (when the page was loaded). I have tried appending the autocomplete line to the end of the post function:

//AJAX Post request that changes the fields in the address div for each different country
$("div#address select#country").live("change", function() {
    $.post("<?php print($_SERVER['PHP_SELF']); ?>", { country: $(this).val() }, function(data) {
        $('div#address').html(data);
    }, "text");
        $('div#address input[type=text]').attr("autocomplete", "off");
});

But for some reason it does not work and the autocomplete pops up when text is entered into any of the address fields. As far as I am aware I cannot use .live() to select the input elements because changing an attribute is not classed as an event.

So can anyone advise me how to modify the attributes of a newly created DOM element?

  • 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-05-14T18:09:57+00:00Added an answer on May 14, 2026 at 6:09 pm

    You need to put the line in your post function after you add the new html to the page.

    $("div#address select#country").live("change", function() {
        $.post("<?php print($_SERVER['PHP_SELF']); ?>", { country: $(this).val() }, function(data){
            $('div#address').html(data);
            $('div#address input[type=text]').attr("autocomplete", "off");
        }, "text");
    });
    

    If you run the javascript the way you have it in your post then the .attr("autocomplete", "off"); is run before the post is complete so it doesn’t apply to the new html. Putting it inside the post function ensures that your new html is on the page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a div on a page where I load a div from another
I have a div (.header) contained within other divs. When my page loads, momentarily
I have multiple divs in a page whose content gets loaded via ajax. I
I have an AJAX link that currently loads a partial view into a div.
I'm using Ajax to dynamically populate a DIV. I have each page content stored
I am setting the innerHTML variable of a div with contents from an ajax
I have a few tabs on my page, whose contents (consisting of many SetView
I have some one page whose div elements are aligned by JavaScript. The JavaScript
I have a div whose content gets dynamically generated from innerHTML and I cant
I have a form whose front page loads up correctly, but whenever I try

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.