Ad
How To Access Angular Attribute Via Javascript Injection
For instance, let's say we have
<div class="row costBreakdown__shipping">
<div class="small-8 medium-7 large-7 columns">Shipping:</div>
<div class="small-4 medium-5 large-5 columns text-right" ng-switch="cart.isRated">
<!-- ngSwitchWhen: true --><div ng-switch-when="true" class="ng-binding ng-scope">$8.48</div><!-- end ngSwitchWhen: -->
<!-- ngSwitchWhen: false -->
</div>
</div>
How would one access the value $8.48 in the class costBreakdown__shipping? I've have
var x = $(".costBreakdown__shipping").eq(2).children().eq(1).children().eq(1)
which gives me
<!-- ngSwitchWhen: true --><div ng-switch-when="true" class="ng-binding ng-scope">$8.48</div>
but how would I go about accessing the value inside?
Ad
Answer
Have you tried using .innerHTML at the end of your assignment value to x?
var x = $(".costBreakdown__shipping").eq(2).children().eq(1).children().eq(1).innerHTML
If you are using Angular, why not assign it to a variable and declare that in your "Shipping" controller (or whatever controller you're using)
<div ng-switch-when="true" class="ng-binding ng-scope">{{shippingCost}}</div>
And in your controller, you can declare
$scope.shippingCost = '$8.48';
Or try shipping cost = 8.48 and apply a filter for currency on the shippingCost in your html
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad