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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:36:29+00:00 2026-06-16T00:36:29+00:00

I am working on a project,i have a div in which i have multiple

  • 0

I am working on a project,i have a div in which i have multiple divs, each div have unique ID(from DB) and each div contains a textbox for adding comment
like below

<div id="maindiv">
<div id="@item.resid">
<p>Content1</p>
<input type="text" class="txtarea" resourceid="@item.resid"/>
</div>
<div id="@item.resid">
<p>Content2</p>
<input type="text" class="txtarea" resourceid="@item.resid"/>
</div>
<div id="@item.resid">
<p>Content3</p>
<input type="text" class="txtarea" resourceid="@item.resid"/>
</div>
<div id="@item.resid">
<p>Content4</p>
<input type="text" class="txtarea" resourceid="@item.resid"/>
</div>

.
.
.
.

i am adding comment by keypress event of textbox, the problem i am having is that when i add comment on content at downside, then after adding the focus comes on top.
I have tried focusing on textbox and even on div but not worked 🙁
below is my code of adding comment

$(".txtarea").keypress(function (e) {
            if (e.keyCode == 13) {
                if ($(this).val().trim() != "") {
                    var commentText = $(this).val();
                    var resourceid = $(this).attr('resourceid');
                    var divId = "." + resourceid;
                    $.ajax({
                        url: ResourceAjaxUrl.AddNewCommentOnResources,
                        type: "POST",
                        data: JSON.stringify({ resourceID: resourceid, commentText: commentText }),
                        dataType: "html",
                        contentType: "application/json; charset-utf-8",
                        success: function (Result) {
                                    $('#maindiv').html(Result);
                                    $('#maindiv div#' + divId.split('.')[1]).focus();
                                    $('#maindiv div#' + divId.split('.')[1]).find(".txtarea").focus();                                    

                        },
                        error: function (msg) {
                            alert("Unable to save comment in");
                        }
                    });
                }
                else {
                    $(this).val('');
                    $(this).focus();
                }
            }
        });

i’ve seen focus() line on developer tool, its working fine but still not focusing, i want that if i add comment on downside(or last) comment, the focus will stay on that instead of going on top

  • 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-16T00:36:29+00:00Added an answer on June 16, 2026 at 12:36 am

    You can’t set a focus on a div. It is for form elements (inputs, textareas, buttons etc.) only.

    Looks like your problem is that you have wrong ID in selector when trying to find a .txtarea:

    success: function (Result) {
                                        $('#maindiv').html(Result);
                                        $('#maindiv div#' + divId.split('.')[1]).find(".txtarea").focus();                                    
    
                            },
    

    $(‘#main div#’ + divId.split(‘.’)[1]).find(“.txtarea”).focus();

    replaced with

    $(‘#maindiv div#’ + divId.split(‘.’)[1]).find(“.txtarea”).focus();

    Besides, once you have a unique ID, you do not need to write $('#maindiv div#' + divId.split('.')[1]). This is enough: $('#' + divId.split('.')[1]) (id must be unique for a whole page anyway, so no need to specify that it is a div located inside #maindiv)

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

Sidebar

Related Questions

I'm working on a project where I have different sets of div like heading,
I am working on a project in which I have two DIVs (DIV1, DIV2),
I'm working on a Rails project in which I have a somewhat of an
I am working on a project which requires jquery scrollTo plugins from Ariel Flesler:
In the project I'm working on, I have a number of divs with photos,
we are working on a project, in which we have to replace html data
I'm working on a project which involves scraping from the major search engines (to
I'm currently working on a new project. I've got a div which acts as
I have this project i'm working on and id like to add a really
I have been working on a project in GWT for which i need to

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.