Richa
Richa

Reputation: 3289

Hide Some Text Using Jquery

So i have this Dynamic html in my code.

  $('#chat-box').html(
                            '<div id="chat-box-msg" style="height:225px;overflow:auto;">' +
                            '<p id="hidepara">Have a question? Let\'s chat!</p><p>Enter your Name & Question in the field\'s below and press ENTER.</p>' +
                            '<p style="margin-top:10px;">Enter Your Name</p><input type="text" id="chat-box-name" style="border:1px solid #0354cb;border-radius: 3px;width: 100%;height:30px;" class="chat-editing" /></div>' +
                            '<div id="chat-box-input"><textarea id="chat-box-textinput" style="width:100%;height:45px;border:1px solid #0354cb;border-radius: 3px;" /></div>'
                        );

This what id do to get text

var todos = $('#chat-box-msg').text();

I was wondering how can i get all html of id "chat-box-msg" and hide the text of paragraph having id "hidepara". So in short i want all html of div except the one having id "hidepara",

Dont be too harsh, i am newbie to jquery.

Thanks a lot

Upvotes: 2

Views: 71

Answers (5)

Balachandran
Balachandran

Reputation: 9637

try

use .filter() to filter the selected element

var filterData = $("#chat-box-msg").children().filter(function (i, element) {
   return element.id != "hidepara";
});

Upvotes: 0

martynas
martynas

Reputation: 12290

You can hide it using .hide():

$('#hidepara').hide();

Upvotes: 1

rajesh kakawat
rajesh kakawat

Reputation: 10906

try something like this

var todos = $('#chat-box-msg').clone().find('#hidepara').remove().end().text();

Upvotes: 2

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67217

Try to exclude the element that you want and just invoke .text() function from the filtered collection,

var text = $('#chat-box-msg').children(':not("#hidepara")').text();

DEMO

Upvotes: 3

Egor Sazanovich
Egor Sazanovich

Reputation: 5089

Just hide element by id

$("#hidepara").hide();

Upvotes: 1

Related Questions