Solved

Jquery repalce hyphens

Posted on 2016-09-04
2
45 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 22

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
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…

910 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

21 Experts available now in Live!

Get 1:1 Help Now