JavaScript - Remove Tag
Hi all, here i got a problem, i want to remove all the Li tag that with a classname"test" .
Code: <html> <head> <title>Introduction to the DOM</title> <script> window.onload = function(){ var li = document.getElementsByTagName("li"); for ( var j = 0; j < li.length; j++ ) { if(li[j].getAttribute('class')=='test'){ li[j].parentNode.removeChild( li[j] ); } } }; </script> </head> <body> <h1>Introduction to the DOM</h1> <p class="test">There are a number of reasons why the DOM is awesome, here are some:</p> <ul> <li class="ppp">ppp.</li> <li class="test">It's easy to use.</li> <li class="test">It can help you to find what you want, really quickly.</li> <li class="test">It's easy to use.</li> <li class="test">It can help you to find what you want, really quickly.</li> <li class="test">It's easy to use.</li> <li class="test">It can help you to find what you want, really quickly.</li> <li class="test">It's easy to use.</li> <li class="test">It can help you to find what you want, really quickly.</li> <li class="test">It's easy to use.</li> <li class="test">It can help you to find what you want, really quickly.</li> <li class="test">It's easy to use.</li> <li class="test">It can help you to find what you want, really quickly.</li> <li class="test">It's easy to use.</li> <li class="test">It can help you to find what you want, really quickly.</li> <li class="test">It's easy to use.</li> <li class="test">It can help you to find what you want, really quickly.</li> </ul> </body> </html> Similar TutorialsHello, I'm currently using this code: I want it so that there isnt a box around the countdown, and the countdown is the same text as "you will be redirected in" here is it in action: http://www.playelite.org/redirect.html Code: <form name="redirect"> <center> <font face="Arial"><b>You will be redirected in: <form> <input type="text" size="3" border="0" name="redirect2"> </form> seconds</b></font> </center> <script> <!-- var targetURL="http://google.com" var countdownfrom=10 var currentsecond=document.redirect.redirect2.value=countdownfrom+1 function countredirect(){ if (currentsecond!=1){ currentsecond-=1 document.redirect.redirect2.value=currentsecond } else{ window.location=targetURL return } setTimeout("countredirect()",1000) } countredirect() //--> </script> Thanks I'm using jQuerys' $.ajax to load a div with some details in it and i want to use the esc key to close the div. Heres the code so far Code: $('.username span').click(function(){ $('.MiniPro').remove(); ID = $(this).parent().attr('ID'); This = $(this).parent(); miniPro(); }); function miniPro() { $(This).append('<div class="MiniPro">Loading...</div>'); $.ajax({ type: 'POST', data: 'userID='+ID, url: 'processing/miniPro.php', success: function(msg) { $('.MiniPro').remove(); $(This).append('<div class="MiniPro"'+msg+'<div class="MiniProClose">X</div></div>'); } }); } Is it even possible to do that? i am doing an edit operation in my web page by changing a image, but when i am revisiting the page it is showing older image rather than new one. So can any one say how to refresh the page without using any button like window.location.reload(). Is there any way to use math.random in url?? Hi Guys, I'm new at JS. I need to remove TR elements from parent table but the problem is there are no table ID/Name Is it possible to perform it? Please see attach - i need remove red marked block... what scrip i have to use if i will put it to the green block? Thank you. I am using this script that gets messed up when you resize the window. I figured out that I could use this other script to do stuff just after the window gets resized. Code: (function($,sr){ // debouncing function from John Hann // http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/ var debounce = function (func, threshold, execAsap) { var timeout; return function debounced () { var obj = this, args = arguments; function delayed () { if (!execAsap) func.apply(obj, args); timeout = null; }; if (timeout) clearTimeout(timeout); else if (execAsap) func.apply(obj, args); timeout = setTimeout(delayed, threshold || 100); }; } // smartresize jQuery.fn[sr] = function(fn){ return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); }; })(jQuery,'smartresize'); // usage: $(window).smartresize(function(){ // code that takes it easy... }); So I re-instantiate the misbehaving script in there so it fires whenever the window is resized (I changed it to 500 so it really only fires once after you are done resizing). This fixes it. The new instance doesn't have a problem but the old instance is still there and messed up. so I use. $($.misbehaving-script).remove(); just before instantiating after window resize, which gets rid of broken instance. Problem solved.. Except that messes up a different script! It's driving me crazy. Any advice would of course be very welcome. Hi I have javascript which calls a load of Java applet functions, there are many of these, and the parameters are all the same. The only thing that changes is the name of the function to call. So here is an example of the Javascript: Code: function answercall() { try { document.frm.response.value = document.Telepop.Answercall(document.telepopfrm.extension.value); } catch(err) { alert(err.description); } } function clearcall() { try { document.telepopfrm.response.value = document.Telepop.Clearcall(document.telepopfrm.extension.value); } catch(err) { alert(err.description); } } function holdcall() { try { document.telepopfrm.response.value = document.Telepop.Holdcall(document.telepopfrm.extension.value); } catch(err) { alert(err.description); } } etc, etc.... and the html like this: <input type="button" value="Answer" onclick="answercall()" /> <input type="button" value="Hangup" onclick="clearcall()" /> <input type="button" value="Hold" onclick="holdcall()" /> There does seem to be a lot of duplication here, so I was wondering of ways to reduce or eliminate the duplication. any ideas? AC I'm working on a webpage where I used this code to display random images. I used it for three images in a row and I keep getting white spacing in between them when they should be right up against each other. This is the code I'm using: Code: <script language="JavaScript"> <!-- /* Random Image Script- By JavaScript Kit (http://www.javascriptkit.com) Over 400+ free JavaScripts here! Keep this notice intact please */ function random_imglink(){ var myimagesblue=new Array() //specify random images below. You can have as many as you wish myimagesblue[1]="images/circles_blue/circle_bl_01.jpg" myimagesblue[2]="images/circles_blue/circle_bl_02.jpg" myimagesblue[3]="images/circles_blue/circle_bl_03.jpg" myimagesblue[4]="images/circles_blue/circle_bl_04.jpg" myimagesblue[5]="images/circles_blue/circle_bl_05.jpg" myimagesblue[6]="images/circles_blue/circle_bl_06.jpg" myimagesblue[7]="images/circles_blue/circle_bl_07.jpg" myimagesblue[8]="images/circles_blue/circle_bl_08.jpg" myimagesblue[9]="images/circles_blue/circle_bl_09.jpg" myimagesblue[10]="images/circles_blue/circle_bl_10.jpg" myimagesblue[11]="images/circles_blue/circle_bl_11.jpg" var ry=Math.floor(Math.random()*myimagesblue.length) if (ry==0) ry=1 document.write('<img src="'+myimagesblue[ry]+'" border=0>') } random_imglink() //--> </script> Is there a way to get the white space removed? Thanks I'm trying to delete a item in a list. I'm getting a method not allowed error in IE8. Code: var selectOptions = document.getElementById('id_employees_cbo'); for (var i=0; i<selectOptions.options.length; i++) { if (selectOptions.options[i].selected == true) { selectOptions.options[i].remove(); break; } } Is there another way to do this? Thanks hello i need help in deleting a code part, like: table, ul ... the problem is that when i use rss feeds, lot of them add some code parts that i don't need like: <ul class="similar-topics">, and it shows similar topics so, i want to remove this code part from the rss feed i think that i may add a javascript code to the rss template that brings the rss feeds, so as it remove the part i define i hope you help me doing this, even with another idea another idea is to use: http://pipes.yahoo.com i"m sure there is a way to cut parts from the code, but i couldn't get it yet and i'm still trying Regards Hello there, I am new to javascript. I would like to remove the div containing a video, by javascript, on the 'onended' event, but am not sure how to do this yet. Here is my code so far: Code: <body onload="javascript:showDiv()"> <div class="fullscreen" id="fullscreen"> <video autoplay="autoplay" > <source src="stage.mp4" type="video/mp4" /> <source src="stage.webm" type="video/webm" /> </video> </div> <script> function hideDiv() { if (document.getElementById) { document.getElementById('fullscreen').style.visibility = 'hidden'; } } function showDiv() { if (document.getElementById) { document.getElementById('fullscreen').style.visibility = 'visible'; } } </script> <script> var video = document.getElementsByTagName('video')[0]; video.onended = function(e) { hideDiv(); document.write("<font color=\"white\">Work???</font>"); } </script> I expected the text 'Work???' to be executed after the onended function carries out. However the video is not removed... Thanks in anticipation to your answers.. Zugz So say if my string was.. Code: a = "Hello"; alert(a); How do I get it to say; Code: alert("ello"); So how do I take off the 'H' in this example.. I've been working with this script Code: function changeImage(layer_id, item_id, position) { var theDiv = document.getElementById(layer_id); var theImg = (theDiv != null) ? theDiv.firstChild : null; if (theImg != null) { // If the item id is 0, then just make the image empty lol if (item_id == 0) { theDiv.parentNode.removeChild(theDiv) } else { theImg.setAttribute('src', 'images/' + layer_id + '-' + item_id + '.png'); } } else { var toAppend = '<div id="' + layer_id + '" style="position: absolute; z-index: ' + position + ';"><img src="images/' + layer_id + '-' + item_id + '.png" /></div>'; document.getElementById("item-images").innerHTML += toAppend; } } where layer_id, item_id, and position are all defined elsewhere. I've been trying to get the images to append, and then run this line Code: theDiv.parentNode.removeChild(theDiv) when you click on them consecutively(click to append, click again to remove, so three consecutive clicks would have the image shown and four would not), but all I've succeeded at so far is breaking the script's functionality. Help? I have a check box right now that calls an onClick event. Here is the Input: Code: <input name="usePad" type="checkbox" value="usePad" id="usePad" onclick="showBind('padShow','padOk')" /> Here is the Script: Code: var xmlhttpshowBind; var showBindDiv; function showBind(BindPage,BindDiv) { xmlhttpshowBind=GetXmlHttpObject(); if (xmlhttpshowBind==null) { alert ("Browser does not support HTTP Request"); return; } var url="/scripts/"+BindPage+".php"; showBindDiv=BindDiv; xmlhttpshowBind.onreadystatechange=showBindGet; xmlhttpshowBind.open("GET",url,true); xmlhttpshowBind.send(null); } function showBindGet() { if (xmlhttpshowBind.readyState==4) { document.getElementById(showBindDiv).innerHTML=xmlhttpshowBind.responseText; } } It works great to fill the div called for, but I would like it to remove the div contents if it's unchecked, I'm not sure how to do this?? Any help would be appreciated! Thank you in advance! Hi, Suppose I have this: Code: <a href="#" class="play" onclick="Audio('lol.mp3')"> As you see, when a user will click on the link, it will play an audio. Good! I want to know if I have another button, let's say <button>Remove</button>, how can I disable the "onClick" event on the link above? And also when clicking on a third button <button>Add</button>again, it will enable the function again to work? NOTE: I do not want an HTML5 audio Stop button. This is different. I just want to know how to enable and disable function event. Thank! Code: <!-- Add-in device.js files are placed here --> <div id="deviceScript"></div> What I have been doing is clearing this out when I select a new (add-in) device and append a script tag with its .src file. I have some vague idea that unhooking an external js file might remove its code from memory. If not is there a way to do so? Functions in different script files have the same name - for example, I use start() to set up each device. It seems that the latest device start() overwrites the one in memory - but I am not sure if overwrite means delete last one or whether there is some horrendous build up of dross going on. Any clarification appreciated. Hi Guys, Someone please help me how to add new function to remove the field, i have js script function that add new field as follows Code: <script language="javascript"> fields = 0; function addInput() { if (fields != 10) { var htmlText = " <input type='text' name='friends[]' value='' size='auto' maxlength='45' /><br />"; var newElement = document.createElement('div'); newElement.id = 'new_field'; newElement.innerHTML = htmlText; var fieldsArea = document.getElementById('new_field'); fieldsArea.appendChild(newElement); fields += 1; } else { alert("Only 10 fields allowed."); document.form.add.disabled=true; } } </script> but i need some helps to add new functions for removing field, For any suggest and pointer would be appreciate. Is it possible to convert "xyz123456xyz789" into "123456xyz789"? What I'm trying to say is, remove the first occurence of "xyz" from the string, so that all the other occurrences of "xyz" that aren't the first one, remain. Help is appreciated. Thanks, Jazzo Hi. I have a script which adds table rows dynamically to a table, when I delete a few removes with the jquery .remove(); sometimes the browser hangs and I have to refresh the page to make the page to work. Any ideas? I was thinking to put a sleep or timeout command just after the row removal, because if I remove rows slowly it won't crash, but if you remove 3-4 rows quickly it will crash, please help! Hi, I am new to development in javascript. I want to remove items in an array by passing index values. The index values may have 1 or more values. For example, i have the following array var arr1=new Array("aa","bb","cc","dd","ee","ff"); var index = new Array(); index[] = 3; index[] = 5 Using the above index values, i want the output as "aa","bb","cc","ee" when i used the slice function, i am not getting the desired output like the one above. Can someone please help me out? Thanks Raja Is there a way to do this? Maybe something like this... Code: $("td:contains(' ')").css("display", "none"); Although for whatever reason, the code above isn't working... |