Solved

jQuery - access and remove <br> tag

Posted on 2014-10-12
5
1,086 Views
Last Modified: 2014-10-12
Hi E's,
I have this code, with some <br> tags:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Access and remove elements</title>
<script src="../../ficheiros_apoio/jquery.min.js"></script> 
</head>
<body>
<a class="access_remove">click here to access and remove <br></a>
<p>this is a phrase with some<br><br>we continue with more breaks<br>hello again</p>
<div>this is a line with breaks<br></div>
<a>this line break is for remove<br><br></a>
<p>thank you<br>for all</p>
<script>
$(".access_remove").click(function(){
     //?????????????????????????????
     });
</script>
</body>
</html>

Open in new window

I need to access/remove the <br>'s (<br><br>) in this line
<a>this line break is for remove<br><br></a>
How I do that?

The best regards, JC
0
Comment
Question by:Pedro Chagas
  • 2
  • 2
5 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40375881
You have nothing to identify the element with and there is no point giving code based on a structure that is probably not the actual way it will look
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 310 total points
ID: 40375907
test page : http://jsfiddle.net/7t9x3bum/
$(".access_remove").click(function(){
    $(this).nextAll("a:first").find("br").remove();
});

Open in new window

0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 40376103
Hi @leakim971, you solution just remove one <br>, and I need to remove all <br>'s of the line.

@gary
, suppose in my code I identify the elements, how I remove the br's?
<a class="access_remove">click here to access and remove <br></a>
<p class="first_p">this is a phrase with some<br><br>we continue with more breaks<br>hello again</p>
<div id="new_id">this is a line with breaks<br></div>
<a class="first_a">this line break is for remove<br><br></a>
<p class="second_p">thank you<br>for all</p>

Open in new window

0
 
LVL 58

Assisted Solution

by:Gary
Gary earned 190 total points
ID: 40376106
Then it's easy
http://jsfiddle.net/upjo6jmg/2/
$(".access_remove").click(function(){
$(".first_a").html($(".first_a").html().replace("<br><br>",""))
})

Open in new window

0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 40376110
My apologizes, @leakim971 code remove all br's in the line.
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

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 …
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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…

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

24 Experts available now in Live!

Get 1:1 Help Now