SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2007
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Looping insite UL

    How can I loop inside UL's LI elements in javascript?

    I have a this HTML code.

    Code:
    <script type="text/javascript">
    
    function TagSecildi(oLink) {
    	var content = oLink.innerHTML + ";";
    	var myString = $('mytags').value;
    	var Pos = myString.indexOf(icerik)
    	if( Pos == -1 ) { // not available
    		$('mytags').value = $('mytags').value + content;
    		oLink.className = 'MySelectedTag';
    	} else { // Var
    		myString = myString.substring(0, Pos) + myString.substring(Pos + content.length);
    		$('mytags').value = myString;
    		oLink.className = 'MyNormalTag';
    	}
    }
    </script>
    
    <input name="mytags" type="text" id="mytags" style="width:500px" value="Ajax; Java;">
    
      <ul id='mevcutlar'>
        <li onClick="TagSecildi(this);">Ajax</li>
        <li onClick="TagSecildi(this);">Delphi</li>
        <li onClick="TagSecildi(this);">JavaScript</li>
      </ul>
    I want to change LI tag's style if my input named "mytags" value (spereated with ; ) is equal to LI's content.

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    var lis = document.getElementById("mevcutlar").getElementsByTagName("li");
    for (var i=0; i < lis.length; i++) {
      // do something with lis[i]
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •