SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    820
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    jQuery - get content of element -- not working in FF

    this line is throwing error, ONLY in Firefox....

    Code:
    content = $(this).html();
    setting a property that has only a getter..

    am trying to GET content of element..

    now I thought you could GET an elem's .html()...
    .html() jQuery API and also acc. to this..
    http://stackoverflow.com/questions/5...et-div-content

    I need to replace only partial content inside element, how do I do this if I can't GET the content of it???

    thank you..

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The obvious question is what is "this".

    In what context are you using the statement?

  3. #3
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    820
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code:
    $('ul.dropdown li.top_level:not(.selected) a').each(function(i) {
    	_content = $(this).html();
    	content = _content.substring(4,_content.length);
    	$(this).html('Link ' + content);
    		
    });
    as mentioned, this works fine in Safari and Chrome.. (can't test on IE)
    why on earth won't it work on FF?? this has never happened to me before..

  4. #4
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is it possible to post a sample of the html involved.

  5. #5
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    820
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <ul class="dropdown">
    	<li class="top_level"><a class="first" href="#">Tab One</a>
    		<ul>
    			<li><a class="first" href="#">Sublink One</a></li>
    			<li><a href="#">Sublink Two</a></li>
    			<li><a href="#">Sublink Three</a></li>
    		</ul>
    	</li>
    	<li class="top_level"><a href="#">Tab Two</a>
    		<ul>
    			<li><a class="first" href="#">Sublink One</a></li>
    			<li><a href="#">Sublink Two</a></li>
    			<li><a href="#">Sublink Three</a></li>
    		</ul>
    	</li>
    	<li class="selected top_level"><a href="#">Tab Three</a></li>
    	
    	<li class="top_level"><a href="#">Tab Four</a></li>
    	
    	<li class="top_level last"><a href="#">Tab Five</a></li>
    </ul>

    thank you..

  6. #6
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK I don't understand why

    but

    putting a var before _content and content seems to resolve the problem.

    Code JavaScript:
    $('ul.dropdown li.top_level:not(.selected) a').each(function(i) {
    	var _content = $(this).html();
    	var content = _content.substring(4,_content.length);
    	$(this).html('Link ' + content);
     
    });

  7. #7
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Appears _content is a property of the window object

    See _content property (window) JavaScript

    So it is just _content that needs to have the var

  8. #8
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    820
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    oh my gosh.. I don't believe it.. when in doubt check var names, I guess..

    thank you very much...


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
  •