Solved

Jquery repalce hyphens

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get the number of current month days 2 26
How do you setTimeout in JQuery? 1 22
Using javascript confirmation for a delete in mysql 5 31
Checking data with javascript 3 19
Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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…

772 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