Solved

jQuery - access and remove <br> tag

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

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses

617 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