Solved

jQuery - access and remove <br> tag

Posted on 2014-10-12
5
1,172 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
$q.all is slower or not  in  Angularjs 2 21
ajax jquery 3 25
suddenly angular cli doesn't work. 5 39
HowTo set a global variable in javascript or jQuery 4 21
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.
This article discusses how to create an extensible mechanism for linked drop downs.
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)
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…

839 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