Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

jQuery - access and remove <br> tag

Posted on 2014-10-12
5
Medium Priority
?
1,407 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
[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
  • 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 1240 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 760 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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

722 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