What is the correct method for inserting a div block?

Here is some code that I have which converts simple text to a textarea field:

        $('.field').on({      
            mouseenter:
                function()
                {
                    title='<?php echo $user_title; ?>';
                    old_value=$(this).text();
                    item_id=$(this).attr('id');
                    item=$(this).parent('td');
                    height=event.target.offsetHeight;
                    width=event.target.parentNode.offsetWidth;
                    new_value=(old_value=='Not translated') ? '' : old_value;
                    $(this).empty();
                    var field=(title=='Login') ? "<textarea style='vertical-align: middle; font-family: Helvetica; font-size: 12pt; width: 212px;' id='new_value' name='term'>" + new_value + "</textarea>" 
                                : "<textarea style='vertical-align: middle; font-family: Helvetica; font-size: 12pt; width: 212px;' id='new_value' name='term'>" + new_value + "</textarea><div id='save_button' class='btn btn-primary' href='#'>>></div>";
                    $(this).html(field);
                    $("#new_value").height(height);
                    button_id=item_id.split('/')[0];
                    button_id=button_id.replace(/([!"#$%&'()*+,./:;<=>?@\[\\\]^`{|}~])/g, "\\$1");
                    $("#"+button_id).show();

                    $("#new_value").click(function()
                    {
                        if (title=='Login') 
                            window.location.replace('<?php echo $fb_url?>');
                    });
                },
            mouseleave:
                function()
                {
                    $(this).empty();
                    $(this).html(old_value);
                    $("#"+button_id).hide();
                    alert($(this).html());
                }
            }
        );

Here is the div block for the text:

echo "<td width='250'><div class='field' id='".$record['translate']['label_value']."/".$record['language_id']."'>".
strip_tags($record['translate']['coalesce(loc.language_value)'])."</div>";

Initially, everything was working fine. But now, I need to add an additional div block:

echo "<td width='250'><div class='field' id='".$record['translate']['label_value']."/".$record['language_id']."'><div style='width: 200px;'>".
strip_tags($record['translate']['coalesce(loc.language_value)'])."</div></div>";

After making this change, my code stopped working as expected! It still changes the text to a textarea field, but in the "mouseleave" event, the $(this).empty() function does not work properly. Can someone please help me fix this issue?

Answer №1

Make sure to properly close your tag

echo "<td width='250'><div class='field' id='".$record['translate']['label_value']."/".$record['language_id']."'><div style='width: 200px;'>".strip_tags($record['translate']['coalesce(loc.language_value)'])."</div></div></td>";

I made an addition at the end

Answer №2

Remember to properly close the TD tag immediately after the closing DIV tag.

echo "<td width='250'><div class='field' id='".$record['translate']['label_value']."/".$record['language_id']."'>".
                                        strip_tags($record['translate']['coalesce(loc.language_value)'])."</div>";

You have overlooked closing the TD tag and also forgot to add a single quote for the id attribute.

  echo "<td width='250'><div class='field' id='".$record['translate']['label_value']."/".$record['language_id']."'>".strip_tags($record['translate']['coalesce(loc.language_value)'])."'</div></td>";

The code should function correctly in this manner. Make sure all your HTML tags and attributes are valid.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to automatically close one menu when another is opened by clicking?

When all other search results have failed to solve my issue, I resort to posting my own question. My problem involves opening hidden submenus in a website's main menu. However, when I open multiple submenus, they just stack above each other. Ideally, ...

Examples of fields rendered using Flask-WTF

When comparing wtforms fields to <input> tags, some equivalents are easily guessed, while others leave me puzzled. Are there any live web pages available where I can test out rendered wtform fields? Or perhaps a collection of templates for wtforms ...

Modify the background's color and incorporate a pointlight using three.js

Recently, I have been exploring the capabilities of three.js. One interesting challenge I encountered was creating a cube within a wireframe cube. However, I found myself struggling to alter the background color in my project. I believe that incorporating ...

Tips on utilizing koa2 for streaming a video file:

I am looking to use Koa2 for streaming my video files, with support for HTTP 206 (Partial Content) requests. The code is functioning properly on Firefox but encountering issues in Chrome. In Chrome, the video request is only made once and then stops requ ...

Is my Magento journey on the correct course?

I am wanting to include or require a file in DATA.php within magento. Below is the code snippet I have: public function formatPrice($price) { require_once(Mage::getBaseDir('app').'\design\frontend\neighborhood ...

Exploring the Differences Between HTML and Javascript

There is something on my mind. In the chat website that I am developing, I have it set to check the database every 10 seconds for new data. Whenever a user posts a comment, it automatically adds it to the list without refreshing the page, although it reloa ...

Delayed data binding in Angular 7 is causing issues

My current struggle involves Angular's data binding delay. After altering the value of this.notAvailable, the frontend doesn't update the [class.hide] until about 5 seconds after execution. Oddly enough, the console.log outputs appear promptly ...

What is the method for replacing browser bundle sources using Rollup?

Is it possible to use rollup to swap out a specific source with another source in an NPM package when creating a browser bundle? The source in question is loaded dynamically using import('./relativeFile.js') (I need this to be replaced). I attem ...

Retrieve data from JSON using AJAX

I am working with an API that provides JSON data in the following format: [{ "Code": "001", "Name": "xyz", "Members": [{ "FullName": "User1" }] }, { "Code": "002", "Name": "asd", "Members": [{ "FullName": "User2 ...

Version 5 of Material UI has a bug where the Grid component does not properly stretch

How can I make the Grid component stretch when one of the Card components contains extra text? You can view the sample code here. Changing the alignItems property to "flex-end" or "center" works, but when using alignItems: "stretch" it does not work. I ...

Exploring TypeScript: Optional Sub-Properties

I've been exploring ways to create a type-alias with properties like "answer" that I came across in this post by another user (Typescript interface optional properties depending on other property). Here's an example: type Sample = { key1: true, ...

"I'm experiencing an issue in Laravel where the Ion range slider's color and dragger are

I'm currently implementing ion-rangeslider into my project. Here is the HTML code I've used: <div style="position: relative; padding: 200px;"> <div> <input type="text" id="range" value="" name= ...

The functionality of the "Slots" prop has no impact when used on the material-ui Slider component

Trying to understand the purpose of the "slots" prop in relation to customizing how inner components like track and thumb are rendered within the Slider component. A basic example of rendering a Slider component is shown below const marks = [ { value: 0 ...

Is it possible to design a collapsible element that gives a sneak peek of its content before fully expanding?

In the title, I mentioned that I require the collapsible to display its content partially before expanding and then fully after expanding. To illustrate this concept, here are two drawings for reference: https://i.sstatic.net/f4CHh.png https://i.sstatic. ...

Acquiring data from an XMLHttpRequest in PHP

I am currently using an ajax request to submit a form, which sends values to a PHP script that stores the data in a database. The following is my ajax post: $.ajax({ type:"POST", url: "wp-content/plugins/super- ...

Filtering out strings of a certain length from an array in JavaScript

Currently working on creating a Wordle game using React. To do this, I require a list of strings. To obtain this list, I am fetching an array of strings from the following API: The challenge lies in the fact that I am interested only in words with a lengt ...

Are you seeking to conduct a long-polling poll with a connectionToken in Visual Studio 2015?

In my current Visual Studio 2015 debug mode session, I noticed that there is a repeated call being made (something I have never experienced with Visual Studio 2012). https://i.sstatic.net/ETvon.png Upon further inspection, I discovered that the call is r ...

How can you ensure that the right data types are sent through ajax requests?

My goal is to ensure the server receives data in the correct data type when using ajax. For example, I want boolean values to be received as actual booleans, integers as integers (not strings), and so on. I attempted a solution where I sent the data as JS ...

What is the most efficient way to transfer an object between two functions in AngularJS?

As a beginner in AngularJS and Javascript, I recently attempted to pass an object from one function to another. Here is the HTML Code: <div ng-click="getValueFromHtml(userObj)">send Object </div> This is the Controller Code: $scope.getValueFr ...

I am consistently encountering the error message: "Error: Unable to locate module './framer'"

I've been running into the same issue repeatedly. I'm in the process of creating a website for a barbershop and I'm attempting to integrate events into a Google calendar using the Google API. I've installed googleapis and framer, but I ...