Solved

Jquery repalce hyphens

Posted on 2016-09-04
2
34 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
2 Comments
 
LVL 21

Accepted Solution

by:
Kim Walker earned 500 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

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 …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn how to dynamically set the form action using jQuery.
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)

707 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

17 Experts available now in Live!

Get 1:1 Help Now