?
Solved

how to text between br tags using jquery

Posted on 2013-12-11
6
Medium Priority
?
1,318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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
Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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 …
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Suggested Courses

770 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