简体   繁体   中英

How to access variable jQuery.fn.init objects

I have a function that is addInputToForm(inputConfig)

in the function there is a $el

In short the function creates label and input element for $el

The new $el is a hyperlink field and I do not need the label portion of the $el

Using Chrome Developer tools and console I can type out

 $el   //Hit return and the result is
 jQuery.fn.init[a#Label Text]  // with triangle to expand
    + 0: a#Label Text  // then an object array displays
       accessKey:
       ...
       innerhtml: "Label Text"
       outerhtml: "Label Text"

My question is how do I access these values because I need to change the Text to "" to be blank.

When you see something like

jQuery.fn.init[...

in the browser console, it means you're looking at a jquery object / collection and so you can apply jquery methods to that object.

For example, to clear the text of a label within an outer element:

$el.find("label").text("");

For a simple demonstration of the console output, view the result of the below in the browser console (not the snippet console doesn't out the same):

 var d = $("#d") console.log(d)
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id='d'>div 1</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM