Solved

how to text between br tags using jquery

Posted on 2013-12-11
6
1,254 Views
Last Modified: 2013-12-11
I want to change the color of the text "Password must be reset".how to find this text in jquery?

able to find "Change Password" text using this script.

console.log( $("#text-id h1").html().split("<br>")[0]);

<div id="text-id" class="signtext" style="">
Sign in to XXX
<h1>
Change Password
<br>
<br>
Password must be reset.
</h1>
</div>

Open in new window

0
Comment
Question by:chaitu chaitu
6 Comments
 
LVL 1

Expert Comment

by:husnilkhatimi
ID: 39711040
All the texts are in the same DIV.

1. You need to create a separated DIV for the "Password must be reset." and put a special class for it.
2. Add new CSS rule with the color you want inside the css file.

Example :
<div id="text-id" class="signtext" style="">
Sign in to XXX
<h1>
Change Password
</h1>
</div>
<br>
<br>
<div id="text-id" class="passwordtext" style="">
<h1>
Password must be reset.
</h1>
</div>

Open in new window

0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 39711043
can't we acheive this without adding new div tag?
0
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 39711047
Hi,
the easiest would be to simply use a replace:
$(document).ready(function () {
    var oldContent = $("#text-id").html();
    $("#text-id").html(oldContent.replace("Password must be reset.","<span class='highlight'>Password must be reset.</span>"));
});

Open in new window


Sample:
http://jsfiddle.net/EE_RainerJ/vTsr5/

HTH
Rainer
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 20

Author Comment

by:chaitu chaitu
ID: 39711052
why "Password must be reset" text is not coming for below script.
to create new div tag first i need to find out the text right..
need to create another div tag after br tag..how to do it?i need to do it dynamically?

console.log( $("#text-id h1").find("br" ).next().next().html());
0
 
LVL 22

Expert Comment

by:Mrunal
ID: 39711058
hi
you will not get this to be executed.
Reason:

$("h1").text() will give you complete string not separated by <br/> tag.

So the solution for this is:
Update your design/html code like:

<p id="CPWD">
Change Password</p>
<br>
<br>
<p id="RPWD">Password must be reset.</p>

and then write simple jQuery function:

alert($("#RPWD").text());

Hope this helps you.
0
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 39711086
Just use a SPAN tag - easy :)

//HTML
<div id="text-id">
   <h1>Change Password<br><br><span>Password must be reset.</span></h1>
</div>

//jQuery
$('#text-id h1 span').text('something new');

Open in new window

0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question