[Solved] jQuery .each() function – Which method is optimized? [closed]

I’d use map(), because it’s there for this very purpose (no need for temp array) var textLinks = $(“a”).map(function(){ return $.trim($(this).text()); }); Edit: If I was looking for the fastest solution I’d start with ditching jQuery 😉 var textLinks = (Array.prototype.slice.call(document.links)).map(function(a){ return a.textContent || a.innerText }) Or if you’re concerned about browsers without Array.map use … Read more

[Solved] Display other field onchange

Try this HTML <select id=”cboCountry”> <option value=”USA”>USA</option> <option value=”OTHERS”>OTHERS</option> </select> <select id=”cboState” name=”cboState”> <option value=”Alabama”>Alabama</option> </select> <input type=”text” id=”txtcboState” name=”cboState” style=”display:none;”/> JS $(“#cboCountry”).change(function() { if ( $(this).val() == “OTHERS”) { $(“#cboState”).hide(); $(“#txtcboState”).show(); } else{ $(“#cboState”).show(); $(“#txtcboState”).hide(); } }); Note: ID Must be unique for each element. To remove The name attribute of input, you can … Read more

[Solved] Jquery to navigate through div [closed]

Here you go. EDIT If you want to go to new page after last div just add else statement and add some attribute to send url. $(“#button”).on(‘click’, function() { var visible = $(“[id^=div]:visible”), number = parseInt(visible.attr(‘id’).substr(3)) + 1, nextDiv = $(“#div” + number); if (nextDiv.length > 0) { visible.hide(); nextDiv.show(); } else { location.href = … Read more

[Solved] Changing img src in jQuery

check to HTML <ul class=”social-media-nav-center”> <li> <a href=”https://twitter.com/” target=”_blank”><img id=”twitter” class=”small” src=”https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRgdlWvqZIB0r6qkjFS_t9uMKD9gQIVMV3fE-Vw9BMoRfNEmJG2″ /> </a> </li> </ul> Jquqey $(document).ready(function(){ $(window).scroll(function(){ if($(window).scrollTop() > $(window).height()) { $(“#twitter”).attr(“src”, “http://www.planwallpaper.com/static/images/744081-background-wallpaper.jpg”); } }) }) CSS .social-media-nav-center{height:1000px;} https://jsfiddle.net/yakcbanL/ 2 solved Changing img src in jQuery

[Solved] change to using jquery

First, in your try example you are replacing input’s parent with select. Second, You have a lot of quotation typos. That would do: var input = $(‘#input’); if(input){ input.replaceWith(“<select id=’input’>” + “</select>”) } Also if you want to keep ‘#’ in your ids, escape them as freedomn-m suggested solved change to using jquery

[Solved] Text change when background colour changes using Javascript

Simply have the text in an array, ( get it from some elements using jquery – however you want it) iterate through it and change the content inside the div using html() function when you are changing the color. Simple modification of your code would be something like function changeColorAndText(element, curNumber){ curNumber++; if(curNumber > 4){ … Read more

[Solved] how do I cycle through background images by clicking a button?

You should also try this. Here conditions are written before setting CSS, which will check first and then assign the image path. $(document).ready(function() { var i = 0; $(“#n”).click(function() { i++; if (i > 13){ i = 1; }; $(‘body’).css(‘background-image’, ‘url(images/bg/’ + i + ‘.png)’); //if (i === 13){ i = 1; }; }); $(“#p”).click(function() … Read more

[Solved] Why do my if/else statement not work?

jQuery has no innerHTML, it has html() instead. A single = is assigment, two == is non-strict comparison, three === is strict comparison. There’s no need for the if/else here at all, just use the proper methods, like html() with a callback $( document ).ready(function(){ var stake_month = 0; var profit_month = 0; var month_games … Read more

[Solved] JSON Parse : Uncaught SyntaxError: Unexpected token , JavaScript [closed]

Objects in JSON are represented with {}. Object have key-value pairs. For example: { “foo”: “bar”, “example: “something”, “key”: “value” } Arrays in JSON are represented with []. They are a list of numbers, strings, objects, etc. For instance: [ “foo”, “bar”, “something”, “example” ] You’re problem is that you are using {} for an … Read more

[Solved] Variables from div

Your question lacks a lot of detail. Can there be more than those four names? Can’t you restructure your code to get an easier access to the data? var toParse = document.getElementById(‘names’).innerHTML; var m; var re = /\[(.*)\]/g; while (m = re.exec(toParse)) { console.log(m[1]); } (https://jsfiddle.net/hL4bu5j1/) This code looks for text in [Bracers] and outputs … Read more

[Solved] Changing background opacity with jQuery [duplicate]

you can use a trick like this set the background to the :after .one:after { background: url(‘http://carwallstar.com/wp-content/uploads/2014/11/ford-car-images2015-ford-mustang–2015-ford-mustang-29—–froggpondcom-w8lqchv6.jpg’) 100% 100% no-repeat; background-size: cover; content: “”; opacity: 0.5; top: 0; left: 0; bottom: 0; right: 0; position: absolute; z-index: -1; } source: https://css-tricks.com/snippets/css/transparent-background-images/ 1 solved Changing background opacity with jQuery [duplicate]

[Solved] Looping javascript multi array

Three loops for each array. Just loop through every array, and append to new array. var size = [‘s’,’m’]; var color = [‘red’,’blue’,’black’]; var material = [‘cotton’,’linen’]; var arrayMaterials = [] for (var i = 0; i < size.length; i++) { for (var j = 0; j < color.length; j++) { for (var k = … Read more

[Solved] How can I save the id of a div tag to a database when clicked and without refresh? [closed]

jQuery, or javascript in general, can’t really connect directly to a database like you are describing. If you have an endpoint to hit, then jQuery (or vanilla javascript, really) could just fire a request to that endpoint with the specific data: $(‘input:file’).on(‘change’, function(event) { $.ajax({ url: ‘/path/to/endpoint’, type: ‘post’, data: { filename: $(this).val() } }); … Read more