Click here to Skip to main content
15,037,168 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
the following HTML is given below pls help me

XML
<div class="col-lg-6 col-md-6 col-sm-12">
                   <input type="text" onfocus="if(this.value == '  Select Start Date') {this.value=''}" onblur="if(this.value == ''){this.value ='  Select Start Date'}" class="txtbox hasDatepicker" id="txtStartDate" name="txtStartDate">
                        <span class="val" id="RequiredFieldValidator4">Start Date is required</span>
                     &nbsp;
                    <span class="abso _icon clender"></span>
                </div>
Posted

You can try this:

PHP
$(function () {
    $("div.col-lg-6").each(function () {
        var $this = $(this);
        $this.html($this.html().replace(/&nbsp;/g, ''));
    });
});



This would remove all the nbsp inside the html of the all the divs with class `col-lg-6`

Demo: FIDDLE[^]

If you want to do it for some specific divs, you can provide some demo class to it and then use the same code by modifying the selector by that class.
   
v5
This could be much more concise but I broke it down anyway.

JavaScript
var removenonBreakingSpace = function(){
 var requiredFieldValidator4 = $('#RequiredFieldValidator4');
 var parent = $(requiredFieldValidator4).parent();

 var html = $(parent).html();

 var formattedHtml = html.replace('&nbsp;','');

 $(parent).html(formattedHtml);
}



Here is my full test page. This works:

HTML
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script type="text/javascript">

        var removenonBreakingSpace = function () {
            var requiredFieldValidator4 = $('#RequiredFieldValidator4');
            var parent = $(requiredFieldValidator4).parent();

            var html = $(parent).html();

            var formattedHtml = html.replace('&nbsp;', '');

            $(parent).html(formattedHtml);
        }

        $(function () {
            removenonBreakingSpace();
        });
    </script>
</head>
<body>
    <div class="col-lg-6 col-md-6 col-sm-12">
        <input type="text" class="txtbox hasDatepicker" id="txtStartDate" name="txtStartDate">
        <span class="val" id="RequiredFieldValidator4">Start Date is required</span>
        &nbsp;
        <span class="abso _icon clender"></span>
    </div>
</body>
</html>
   
v6
Comments
Athul MS 25-Sep-15 6:59am
   
its not working
Andy Lanng 25-Sep-15 7:00am
   
any error? did you step through?
Andy Lanng 25-Sep-15 7:02am
   
I had an error - I have now corrected
Athul MS 25-Sep-15 7:03am
   
there is no error occured
Andy Lanng 25-Sep-15 7:08am
   
You are running the function from somewhere, right? Take a look at the text html page I have added to the solution. I run the function from jQuery doc.ready

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900