Solved

how to text between br tags using jquery

Posted on 2013-12-11
6
1,229 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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)

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now