Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Jquery repalce hyphens

Posted on 2016-09-04
2
Medium Priority
?
72 Views
Last Modified: 2016-09-04
Hello Experts,

Lets take the string "Word-ing", see below,
On large screen the tag <i> is in display block. So the "ing" comes right below the "Word".
On a small screen tag <i> is in display inline and so I need to remove the hyphen right next to the "Word-".

Here is a script i came up with and now my question is how to bring back the hyphen when resize to large screen. The issue is also that my code removes the tag "i" totally, not sure why.

<span class="hyphen">Word- 
   <i>ding</i> 
</span>

Open in new window


$(window).bind('load resize',function() {
			
		if ($(document).width() <= 1023) {
				
			var hyphen = $(".hyphen");
			
			hyphen.each(function() {
			
			$(this).html($(this).text().replace("-",""));
			
			});
		} else {
			
			//$(".hyphen").children("i").before("-");
		}
});

Open in new window

0
Comment
Question by:Refael
[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 Comments
 
LVL 22

Accepted Solution

by:
Kim Walker earned 2000 total points
ID: 41784010
You could put the hyphen in a span by itself and display that span only in your small screen responsive styling.
<span class="hyphen">Word<span class="largescreen">-</span>
   <i>ing</i> 
</span>

Open in new window

/* Default CSS */
span.largescreen { display: none; }

@media screen and ([small screen parameters here]) {
span.largescreen { display: inline; }

Open in new window

0
 

Author Closing Comment

by:Refael
ID: 41784013
Hello Kim, you are so right! What was I thinking trying to resolve this with jQuery. Thank you!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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

636 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