- Screen name: Razvan Zamfir
Razvan Zamfir's Profile
20 Posts
34 Responses
0
Followers
Show:
- Expanded view
- List view
Private Message
- 17-Feb-2019 03:10 AM
- Forum: Using jQuery
I have a set of checkboxes that are intended to toggle the visibility of corresponding form groups.- <div class="form-group" id="backgrounds_picker">
- <label class="col-md-4 control-label" for="checkboxes">
- Select any desired backgrounds:</label>
- <div class="col-md-4">
- <label class="checkbox-inline" for="checkboxes-0">
- <input name="checkboxes" id="checkboxes-0" type="checkbox" value="blank">
- Blanks
- </label>
- <label class="checkbox-inline" for="checkboxes-1">
- <input name="checkboxes" id="checkboxes-1" type="checkbox" value="fresh">
- Fresh Water
- </label>
- <label class="checkbox-inline" for="checkboxes-2">
- <input name="checkboxes" id="checkboxes-2" type="checkbox" value="marine">
- Marine Water
- </label>
- <label class="checkbox-inline" for="checkboxes-3">
- <input name="checkboxes" id="checkboxes-3" type="checkbox" value="rain">
- Rain
- </label>
- <label class="checkbox-inline" for="checkboxes-4">
- <input name="checkboxes" id="checkboxes-4" type="checkbox" value="none" checked="checked">
- None
- </label>
- </div>
- </div>
- <div id="fields">
- <div id="blank_co" class="form-group">
- <label class="col-md-4 control-label" for="blankbg">Blanks cutoff: (1-99)</label>
- <div class="col-md-4">
- <input name="blankbg" class="form-control input-md" id="blankbg" required="" type="text" placeholder="" value="10">
- </div>
- </div>
- <div id="fresh_co" class="form-group">
- <label class="col-md-4 control-label" for="freshbg">Fresh water cutoff: (1-99)</label>
- <div class="col-md-4">
- <input name="freshbg" class="form-control input-md" id="freshbg" required="" type="text" placeholder="" value="10">
- </div>
- </div>
- <div id="marine_co" class="form-group">
- <label class="col-md-4 control-label" for="marinebg">Marine water cutoff: (1-99)</label>
- <div class="col-md-4">
- <input name="marinebg" class="form-control input-md" id="marinebg" required="" type="text" placeholder="" value="10">
- </div>
- </div>
- <div id="rain_co" class="form-group">
- <label class="col-md-4 control-label" for="rainbg">Rain water cutoff: (1-99)</label>
- <div class="col-md-4">
- <input name="rainbg" class="form-control input-md" id="rainbg" required="" type="text" placeholder="" value="10">
- </div>
- </div>
- </div>
The script I have written for the above HTML gives a "Cannot read property 'toLowerCase' of undefined" error in the console instead of just... working.- var $check = $('#backgrounds_picker input[type="checkbox"][value!="none"]'),
- $none = $('input[type="checkbox"][value="none"]'),
- $groups = $('#fields .form-group');
- var uncheckAll = function() {
- if ($(this).is(':checked')) {
- $check.not(this).prop('checked', false);
- }
- }
- var uncheckNone = function() {
- if ($(this).is(':checked')) {
- $none.prop('checked', false);
- }
- }
- var hideGroup = function(){
- $groups.fadeOut();
- }
- var toggleGroup = function(){
- var groupId = $(this).val();
- if ($(this).is(':checked')) {
- $('#' + groupId + '_co').fadeIn();
- } else {
- $('#' + groupId + '_co').fadeOut();
- }
- }
- $none.on('change', function(){
- uncheckAll();
- hideGroup();
- });
- $check.on('change', function(){
- uncheckNone();
- toggleGroup();
- });
Where is my mistake?- 25-Aug-2018 10:50 AM
- Forum: Developing jQuery Plugins
I am working on a custom image carousel, using jQuery and CSS. My aim is to make it really lightweight but with (just) enough features: "bullets", auto-advance, responsiveness.
The slider had a bug (described in detail HERE): when I clicked 2 bullets in rapid succession, the transition would overlap, instead of "standing in line". The fix I found is making all the bullets except the active one non-responsive to clicks, instead of queueing the clicks :
- var $elm = $('.slider'),
- $slidesContainer = $elm.find('.slider-container'),
- slides = $slidesContainer.children('a'),
- slidesCount = slides.length,
- slideHeight = $(slides[0]).find('img').outerHeight(false),
- animationspeed = 1500,
- animationInterval = 7000;
-
- // Set (initial) z-index for each slide
- var setZindex = function() {
- for (var i = 0; i < slidesCount; i++) {
- $(slides[i]).css('z-index', slidesCount - i);
- }
- };
- setZindex();
-
- var displayImageBeforeClick = null;
-
- var setActiveSlide = function() {
- $(slides).removeClass('active');
- $(slides[activeIdx]).addClass('active');
- };
-
- var advanceFunc = function() {
- if ($('.slider-nav li.activeSlide').index() + 1 != $('.slider-nav li').length) {
- $('.slider-nav li.activeSlide').next().find('a').trigger('click');
- } else {
- $('.slider-nav li:first').find('a').trigger('click');
- }
- }
-
- var autoAdvance = setInterval(advanceFunc, animationInterval);
-
- //Set slide height
- $(slides).css('height', slideHeight);
-
- // Append bullets
- if (slidesCount > 1) {
- /* Prepend the slider navigation to the slider
- if there are at least 2 slides */
- $elm.prepend('<ul class="slider-nav"></ul>');
- // make a bullet for each slide
- for (var i = 0; i < slidesCount; i++) {
- var bullets = '<li><a href="#">' + i + '</a></li>';
- if (i == 0) {
- // active bullet
- var bullets = '<li class="activeSlide"><a href="#">' + i + '</a></li>';
- // active slide
- $(slides[0]).addClass('active');
- }
- $('.slider-nav').append(bullets);
- }
- };
-
- var animationStart = false;
- var slideUpDown = function() {
- animationStart = true;
- // set top property for all the slides
- $(slides).not(displayImageBeforeClick).css('top', slideHeight);
- // then animate to the next slide
- $(slides[activeIdx]).animate({
- 'top': 0
- }, animationspeed, function() {
- animationStart = false;
- });
-
- $(displayImageBeforeClick).animate({
- 'top': "-100%"
- }, animationspeed, function() {
- animationStart = false;
- });
- };
-
- $('.slider-nav a').on('click', function(event) {
- if (animationStart) {
- return false;
- }
- displayImageBeforeClick = $(".slider-container .active");
- activeIdx = $(this).text();
- if ($(slides[activeIdx]).hasClass("active")) {
- return false;
- }
- $('.slider-nav a').closest('li').removeClass('activeSlide');
- $(this).closest('li').addClass('activeSlide');
- // Reset autoadvance if user clicks bullet
- if (event.originalEvent !== undefined) {
- clearInterval(autoAdvance);
- autoAdvance = setInterval(advanceFunc, animationInterval);
- }
-
- setActiveSlide();
- slideUpDown();
- });
I have posted a jsFuddle with all the code HERE .
Questions: How can I queue the clicks? Are there any better alternatives to queueing the clicks?
- I have just discovered Barba.js and find it very useful. It provides smooth transitions between URLs of the same website.I have put together a Plunker consisting of two pages (index.html and about.html) that are loaded smoothly, with the help of jQuery’s fadeIn() and fadeOut() methods.
- $(document).ready(function() {
- var transEffect = Barba.BaseTransition.extend({
- start: function() {
- this.newContainerLoading.then(val => this.fadeInNewcontent($(this.newContainer)));
- },
- fadeInNewcontent: function(nc) {
- nc.hide();
- var _this = this;
- $(this.oldContainer).fadeOut(1000).promise().done(() => {
- nc.css('visibility', 'visible');
- nc.fadeIn(1000, function() {
- _this.done();
- });
- $('html, body').animate({
- scrollTop: 300
- },1000);
- });
- }
- });
- Barba.Pjax.getTransition = function() {
- return transEffect;
- }
- Barba.Pjax.start();
- });
The problem with this animations is that there is a white screen interval between them. How could I eliminate this interval, to make the transition smoother?By "smoother" I mean similar to this one (wait 2, 3 seconds, then click "view case"). I mean, an "invisible transition".- 07-Jul-2018 01:43 PM
- Forum: Using jQuery
I have made a horizontal carousel of images (and captions) using Twitter Bootstrap 4 and the perfect-scrollbar plugin.
I want users to be able to navigate by using the mouse wheel. The plugin dos have a handlers option that I did use.
Here is a jsFiddle with what I did so far.
But it does not work the expected way. Like THIS, for instance.
Questions:
- Am I using it wrong, or does the plugin not have such an option?
- What alternatives do I have?
- 30-Jun-2018 04:48 PM
- Forum: Using jQuery
I am working on a small "Picture browser" application in Bootstrap 4 and JavaScript.
As can be seen in THIS jsFiddle, there is a "Prev" and a "Next" button that help navigate through the pictures.
I have bean trying to find a reliable method to make mouse well scrolling function the same as these buttons. Scrolling down would be the equivalent of clicking the "Next" button. Scrolling up would be the equivalent of clicking the "Prev" button.
Firing theshowSlide()
function on mouse wheel does work, but the transition is too... continuous. I wish it would be identical to the transition triggered by the buttons.I would also need to detect and use the mouse well scroll direction.What am I missing? What shall I do?
- 01-Jun-2018 06:08 AM
- Forum: Using jQuery Plugins
I am working on some kind of carousel with items aligned horizontally.
Each of the child elements (there will be about a dozen of them) should stretch one third of the parent's width. Three items should be visible at any one time.
I have used Bootstrap 4, some custom CSS and the Perfect-scrollbar plugin. HERE is a jsFiddle.
It came out pretty nice, except I have been struggling to find a way to set a fixed width (of 300px) for the rail (the gray line) and centering it. How can I do that?
- 23-May-2018 05:01 AM
- Forum: Getting Started
I have a button and an unordered list with its items hidden:
- <button>Show</button>
- <ul id="letters">
- <li>A</li>
- <li>B</li>
- <li>C</li>
- </ul>
The CSS:- #letters li {
- display: none;
- }
I want to show elements in sequence o button click.My script:- var showLetters = function () {
- var letter = $('#letters').find('li');
- letter.each(function() {
- $(this).delay(2000).fadeIn("show");
- });
- }
- $('button').on('click', showLetters);
The script fades the letters in but NOT in sequence. There is s jsFiddle HERE.Why? What is a viable alternative?- 14-Oct-2017 02:01 AM
- Forum: Developing jQuery Plugins
I am building an image slider plugin with Next and Previous buttons and an auto advance feature.
The auto advance happens by triggering clicks on the Next button at equal intervals:
- $(window).on('load', function() {
- autoAdvanceInterval = setInterval(function() {
- $('#next').trigger('click');
- }, settings.pause);
- // When a control or dot is clicked by user
- // stop autoadvance by clearInterval method
- $('.controls a,.bullets li').click(function(event) {
- if (event.originalEvent !== undefined) {
- clearInterval(autoAdvanceInterval);
- }
- });
- });
The auto advance stooped working after updating jQuery from v2.0.0 to v3.2.1. I replaced
$(window).load()
with(window).on('load', ...
but it still does not work.What am I doing wrong? Thank you!
- 13-Oct-2017 01:46 AM
- Forum: Developing jQuery Plugins
I had made a plugin a while ago, it used jQuery v2.1.1. It worked fine. Since using the modern 3.2.1, the console shows this error:
Uncaught TypeError: a.indexOf is not a function at r.fn.init.r.fn.load
I have a piece of code like this:
- function responsiveSlides() {
- var percentageSlidesWidth = (1 / slidesLen) * 100 + '%';
- $slides.width(percentageSlidesWidth);
- }
- $(window).on('load',responsiveSlides());
The last line above seems to cause the error. But what is the fix? Thank you!
- 12-Oct-2017 07:21 AM
- Forum: Using jQuery Plugins
I have made a very light and feature rich jQuery slider plugin. It has a slide left/right transition from one image to the next or previous.
You can see the plugin in action HERE.
It worked very well/as intended until I added bezier transitions to
ul.slider
for smoothness. Since then, on page load it shows the last image instead of the first. How can I avoid that?Also, even though the slider should loop (and it does, in the absence of the bezier transitions), it does not loop.
- 03-Oct-2017 07:38 AM
- Forum: Using jQuery
I have made an accordion menu intended to serve as an efficient mobile phone menu. I have used the jQuery 2.1.1 library for this purpose. The part that does not work as I want it to is that concerning the body tag animation. I want the document to scroll to the active menu item.This is what I came up with:The HTML:- <nav id="menu">
- <ul>
- <li><a href="#" class="menu-item">Software</a>
- <ul class="sub-menu">
- <li><a href="#">Operating systems</a></li>
- <li><a href="#">MS Office</a></li>
- <li><a href="#">Web development tools</a></li>
- </ul>
- </li>
- <li><a href="#" class="menu-item">Monitors & screens</a>
- <ul class="sub-menu">
- <li><a href="#">Monitors</a></li>
- <li><a href="#">LCD</a></li>
- <li><a href="#">TV</a></li>
- <li><a href="#">DVD players</a></li>
- </ul>
- </li>
- <li><a href="#" class="menu-item">Networking</a>
- <ul class="sub-menu">
- <li><a href="#">Routers</a></li>
- <li><a href="#">Network Adapters</a></li>
- <li><a href="#">Modems</a></li>
- <li><a href="#">Cables</a></li>
- </ul>
- </li>
- <li><a href="#" class="menu-item">Print & scan</a>
- <ul class="sub-menu">
- <li><a href="#">Printers</a></li>
- <li><a href="#">3D printers</a></li>
- <li><a href="#">Scanners</a></li>
- </ul>
- </li>
- </ul>
- </nav>
The jQuery:- $('#menu').children('ul').on('click', '.menu-item', function(e) {
- if ($(window).width() < 640) {
- e.preventDefault();
- var $menu_item = $(this).closest('li');
- var $sub_menu = $menu_item.find('.sub-menu');
- var $other_sub_menus = $menu_item.siblings().find('.sub-menu');
- if ($sub_menu.is(':visible')) {
- $sub_menu.slideUp(200);
- $menu_item.removeClass('selected');
- } else {
- $other_sub_menus.slideUp(200);
- $sub_menu.slideDown(200);
- $menu_item.siblings().removeClass('selected');
- $menu_item.addClass('selected');
- }
- }
- $('html,body').animate({
- scrollTop: $(this).offset().top
- }, 500);
- console.log($(this).offset().top);
- });
The CSS:- nav ul {
- list-style-type: none;
- margin: 0;
- padding: 0;
- }
- #menu {
- max-width: 640px;
- }
- #menu ul {
- background: #069;
- }
- #menu ul.sub-menu {
- display: none;
- background: #fefefe;
- }
- #menu ul li a {
- text-decoration: none;
- display: block;
- font-size: 13px;
- color: #fff;
- padding: 0 10px;
- height: 32px;
- line-height: 30px;
- position: relative;
- border-top: 1px solid rgba(0, 0, 0, 0.1);
- border-bottom: 1px solid rgba(255, 255, 255, 0.1);
- }
- #menu ul.sub-menu li a {
- padding-left: 25px;
- color: #555;
- }
- #menu > ul > li > a:after {
- display: inline-block;
- vertical-align: middle;
- content: "\2304";
- position: absolute;
- right: 0;
- font-size: 20px;
- line-height: 20px;
- padding-bottom: 10px;
- width: 30px;
- text-align: center;
- top: 0;
- color: #fff;
- }
- #menu li.selected a:after {
- -webkit-transform: rotate(180deg);
- -moz-transform: rotate(180deg);
- -ms-transform: rotate(180deg);
- -o-transform: rotate(180deg);
- }
Here is a JsFiddle.Console logging the top offset gives an aberrant value if you click multiple menu items successively. As a consequence, the page does not scroll to the begginning of the active item. What ce I do?On THIS page, I have a div with the class of “video-wrapper” witch, upon clicking the player’s toggle full screen button, is dynamically added a “full-screen” class.
I aim to remove the “full-screen” class not only by using the toggle full screen button, but by pressing the “Esc” on the keyboard. foe this purpose I have written the code:
$(document).on('keyup',function(evt) { if (evt.keyCode == 27 && $('.video-wrapper').hasClass('full-screen')) { console.log(evt.keyCode); $('.video-wrapper').removeClass("full-screen"); $('input.fullscreen').removeClass('active'); } });
The problem is that this takes two “Esc” key strokes instead of one. The first just exists the browser’s full screen mode and the second removes the “full-screen” class.
How can I exist the browser’s full screen mode and remove the “full-screen” class with one “Esc” key stroke?
- 07-Apr-2017 03:53 PM
- Forum: Using jQuery Plugins
On this page I have the MP3-jPlayer WordPress plugin with the Text Skin, slightly modified.
I have deleted the volume bar from the plugin’s html/php structure. I have also added a “seekbar”:
- <div class="seekbar-wrapper">
- <div class="seekbar-container">
- <div class="seekbar" value="0" max="1"></div>
- </div>
- </div>
I have modified the plugin’s mp3-jplayer-2.7.js file in order to show, for every track (mp3 files), the timeline. After line 403 (
jQuery(this.eID.indiM + j).empty().append('<span class="Smp3-tint tintmarg"></span> ' + this.Tformat(pt));
) I have added:- var sbContainerWidth = $('.seekbar-container').width();
- var progValue = pt / tt * 100;
- var progPercentage = progValue + '%';
- $('#mp3jWrap' + '_' + this.tID).closest('li').find('.seekbar').width(progPercentage);
The result of this is the presence of a progress bar that was missing before.
I have tried to make the seekbar react to a click event and update the track’s "timer:
- var sbContainerWidth = $('.seekbar-container').width();
- function skip(ev) {
- pt = ev.pageX - $('.seekbar-container').offsetLeft;
- }
But unfortunately it does not react to the clicking (and the timeline does not update).
Why? Where is the mistake?
- On this page I have the MP3-jPlayer plugin with the Text Skin, slightly modified. I need to show, for every track (mp3 files), the timeline instead of the volume bar. How do I do that?
- 16-Mar-2017 04:25 PM
- Forum: Using jQuery
On urbansunsets.com, I have implemented radio streaming in HTML5 and JavaScipt (jQuery). There is an error on iPhones.The code:HTML- <div class="col-lg-12 col-sm-12">
- <div id="radio_player">
- <div class="default-player">
- <audio width="320" height="240" controls playsinline id="audio_player">
- <source id="player_source" src="http://public.radio.co/stations/sedf8bacc9/m3u" type="audio/mpeg">
- </audio>
- </div>
- <div id="audioplayer">
- <button id="pButton" class="pause"></button>
- <div class="live">Livee</div>
- <div id="volume_control">
- <label id="rngVolume_label" for="rngVolume">
- <i class="fa fa-volume-up" aria-hidden="true"></i>
- </label>
- <input type="range" id="rngVolume" min="0" max="1" step="0.01" value="0.5">
- </div>
- <div class="current-piece">
- <div class="now-playing">Now playing:</div>
- <div id="song_name">
- <script src="https://public.radio.co/embed/sedf8bacc9/song.js"></script>
- </div>
- </div>
- </div>
- </div>
- </div>
jQuery:- (function() {
- setTimeout(function(){
- document.getElementById("audio_player").play();
- }, 300);
- var music = document.getElementById('audio_player');
- function playAudio() {
- if (music.paused) {
- music.play();
- pButton.className = "";
- pButton.className = "pause";
- } else {
- music.pause();
- pButton.className = "";
- pButton.className = "play";
- }
- }
- $('#pButton').on('click', playAudio);
- $(function() {
- var timeout
- $("audio").on({
- pause: function() {
- clearTimeout(timeout)
- },
- play: monitor
- })
- $("#rngVolume").on("input",function(){
- $("audio").prop("volume",this.value)
- })
- });
- function monitor() {
- $("#rngVolume").val($("audio").prop("volume"))
- $.ajax("https://public.radio.co/stations/sedf8bacc9/status", {
- cache: false
- }).then(function(data) {
- $(".title").text(data.current_track.title)
- $(".data").text(JSON.stringify(data, 4, 4))
- $(".artwork").attr("src", data.current_track.artwork_url)
- timeout = setTimeout(monitor, 1000 * 60)
- })
- }
- })();
The error:Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause().I have only seam it on iPhones.What is the cause of this error?On urbansunsets.com I am streaming online radio from radio.co. It does work, but after a period of continuous playing, there is a delay at the part that shows what is currently playing.
- <div class="col-lg-12 col-sm-12">
- <div id="radio_player">
- <div class="default-player">
- <audio width="320" height="240" controls playsinline id="audio_player">
- <source src="http://stream.radio.co/sedf8bacc9/listen" type="audio/mpeg">
- </audio>
- </div>
- <div id="audioplayer">
- <button id="pButton" class="pause"></button>
- <div class="live">Live</div>
- <div id="volume_control">
- <label id="rngVolume_label" for="rngVolume">
- <i class="fa fa-volume-up" aria-hidden="true"></i>
- </label>
- <input type="range" id="rngVolume" min="0" max="1" step="0.01" value="0.5">
- </div>
- <div class="current-piece">
- // Current piece
- <div class="now-playing">Now playing:</div>
- <script src="https://public.radio.co/embed/sedf8bacc9/song.js"></script>
- </div>
- </div>
- </div>
- </div>
In jQuery, I have put together a small script to force reload the script that shoes the current track:- function showCurrSong() {
- var currSongScript = document.createElement('script');
- currSongScript.src= 'https://public.radio.co/embed/sedf8bacc9/song.js';
- $('#song_name').html('');
- $('#song_name').append(currSongScript);
- console.log(currSongScript);
- }
- var refreshTime = 1000 * 60 * 3; // minutes
- setInterval(function(){showCurrSong()}, refreshTime);
But that replaces the "frozen" old track name with "Loading...".
Why is that?
Thank you!
- 03-Oct-2016 04:44 AM
- Forum: Using jQuery
On THIS page I have a bunch of "placeholders" for phone numbers in the form: 07xxxxxxxx. Upon clicking the green button "VEZI TELEFON", the placeholder in each green box is replaced with a real phone number from a JSON file, via $.ajax.The console strangely shows 2 different things on desktop and mobile. The value of index is different it seams... Desktop:
Mobile:0: 0743127315 1: 072245875 3: 0756129668 4: 0724153333 Uncaught TypeError: Cannot read property 'tel' of undefined
1: 072245875 2: 0756129458 4: 0724153333 Uncaught TypeError: Cannot read property 'tel' of undefined
The JS code:{ "telefoane": [{ "id": 1, "tel": "0743127315" }, { "id": 2, "tel": "072245875" }, { "id": 3, "tel": "0756129458" }, { "id": 4, "tel": "0756129668" }, { "id": 5, "tel": "0724153333" }] }
What is wrong with this code? Thank you!function showTel() { $(".telefon").on('click', function(){ var index = $(this).closest(".imobil").index(); var $element = $(this); $.ajax({ url: 'telefoane.json', dataType: 'json', type : 'get', cache : 'false', success: function(data){ var tel = data.telefoane[index].tel; console.log(index + ": " + tel); $element.parent().find('.telefon .tel').text(tel); } }); }); } showTel(); // Arata telefon $('.telefon').on('click', function(){ $(this).children('.vezi').hide(); $(this).children('.tel').show(); });
- On THIS page, I have listed some dummy estates and hard-coded, for each one, a span (with the text "VEZI TELEFON") that when clicked, reveals a phone number. I want every phone number to be retrieved from a JSON (or PHP) file called telefoane.json that has the content:
{ "telefoane":[{ "id":"1", "tel":"0743127315" }, { "id":"2", "tel":"072245875" }, { "id":"3", "tel":"0756129458" }, { "id":"4", "tel":"0725127216" }, { "id":"5", "tel":"0723127322" }]
My code, that can be seen below does not output the desired result:
$.ajax({ url: 'telefoane.json', dataType: 'json', success: function(data){ $.each(data.telefoane, function() { console.log(this.id + ": " + this.tel); }); } });
What am I doing wrong? Thank you!
- 13-Aug-2015 11:12 AM
- Forum: Using jQuery Plugins
I have modified fastLiveFilter jQuery plugin by adding a highlight functionality.I added a button to the form:<form id="search_box"><input type="text" id="search_input" name="search_box" /><input id="search-button" type="button" value="Search" role="button" /></form>The search/filter is not trigger on keyup, but on pressing the button or the [ENTER] key.The function bellow wrapps the searched string in a span:function highlightTerm(){var searchTerm = $(input).val();$(lis).each(function(){var liText = $(this).html();var regex = new RegExp(searchTerm, 'gi');var found;var inc = 0;while((found = regex.exec(liText)) !== null) {if (inc += 1 > 100) {throw 'An infinite loop will occur.';}var word = found[0];var lastChar = found.index;var left = liText.substring(0, lastChar);var right = liText.substring(lastChar + word.length);var insert = '<span class="highlight">' + word + '</span>';// regex.lastIndex = regex.lastIndexliText = left + insert + right;regex.lastIndex = (regex.lastIndex - word.length) + insert.length;}$(this).html(liText);});}The search is case INSENSITIVE.The problem is that the searched string is wrapped in the span with the class "highlight" even if found in URL on the page. So the function above ruins the links. How do I avoid this?To be more clear: I want to match a word stored in a variable searchTerm. If searchTerm is "test", it should me match (and wrapped with a span) in "This it a test" but not in <a href="my-test.html">word</a>.Thank you!
- 23-Jun-2015 10:50 AM
- Forum: Using jQuery
I have made an HTML5 responsive, 2 levels menu you can see HERE The wide screen version shows submenus upon hovering over the main menu items; the narrow screen (less then 800px) version shows submenus upon clicking the main menu items.
The problem is that, if I resize the window, the switch between hover and click events does not happen properly. Of course, I want the menu to react at click on mobile devices...
What shall I change in my script? Or is there an already made solution that I can use?
Thank you!
- «Prev
- Next »
Moderate user : Razvan Zamfir
© 2013 jQuery Foundation
Sponsored by
and others.